Passed
Push — master ( d8d15c...f4adfd )
by
unknown
14:53 queued 13s
created
lib/private/Command/CommandJob.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -29,12 +29,12 @@
 block discarded – undo
29 29
  * Wrap a command in the background job interface
30 30
  */
31 31
 class CommandJob extends QueuedJob {
32
-	protected function run($serializedCommand) {
33
-		$command = unserialize($serializedCommand);
34
-		if ($command instanceof ICommand) {
35
-			$command->handle();
36
-		} else {
37
-			throw new \InvalidArgumentException('Invalid serialized command');
38
-		}
39
-	}
32
+    protected function run($serializedCommand) {
33
+        $command = unserialize($serializedCommand);
34
+        if ($command instanceof ICommand) {
35
+            $command->handle();
36
+        } else {
37
+            throw new \InvalidArgumentException('Invalid serialized command');
38
+        }
39
+    }
40 40
 }
Please login to merge, or discard this patch.
lib/private/Template/ResourceNotFoundException.php 2 patches
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -24,23 +24,23 @@
 block discarded – undo
24 24
 namespace OC\Template;
25 25
 
26 26
 class ResourceNotFoundException extends \LogicException {
27
-	protected $resource;
28
-	protected $webPath;
27
+    protected $resource;
28
+    protected $webPath;
29 29
 
30
-	/**
31
-	 * @param string $resource
32
-	 * @param string $webPath
33
-	 */
34
-	public function __construct($resource, $webPath) {
35
-		parent::__construct('Resource not found');
36
-		$this->resource = $resource;
37
-		$this->webPath = $webPath;
38
-	}
30
+    /**
31
+     * @param string $resource
32
+     * @param string $webPath
33
+     */
34
+    public function __construct($resource, $webPath) {
35
+        parent::__construct('Resource not found');
36
+        $this->resource = $resource;
37
+        $this->webPath = $webPath;
38
+    }
39 39
 
40
-	/**
41
-	 * @return string
42
-	 */
43
-	public function getResourcePath() {
44
-		return $this->webPath . '/' . $this->resource;
45
-	}
40
+    /**
41
+     * @return string
42
+     */
43
+    public function getResourcePath() {
44
+        return $this->webPath . '/' . $this->resource;
45
+    }
46 46
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -41,6 +41,6 @@
 block discarded – undo
41 41
 	 * @return string
42 42
 	 */
43 43
 	public function getResourcePath() {
44
-		return $this->webPath . '/' . $this->resource;
44
+		return $this->webPath.'/'.$this->resource;
45 45
 	}
46 46
 }
Please login to merge, or discard this patch.
lib/private/Memcache/CASTrait.php 2 patches
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -23,35 +23,35 @@
 block discarded – undo
23 23
 namespace OC\Memcache;
24 24
 
25 25
 trait CASTrait {
26
-	abstract public function get($key);
26
+    abstract public function get($key);
27 27
 
28
-	abstract public function set($key, $value, $ttl = 0);
28
+    abstract public function set($key, $value, $ttl = 0);
29 29
 
30
-	abstract public function remove($key);
30
+    abstract public function remove($key);
31 31
 
32
-	abstract public function add($key, $value, $ttl = 0);
32
+    abstract public function add($key, $value, $ttl = 0);
33 33
 
34
-	/**
35
-	 * Compare and set
36
-	 *
37
-	 * @param string $key
38
-	 * @param mixed $old
39
-	 * @param mixed $new
40
-	 * @return bool
41
-	 */
42
-	public function cas($key, $old, $new) {
43
-		//no native cas, emulate with locking
44
-		if ($this->add($key . '_lock', true)) {
45
-			if ($this->get($key) === $old) {
46
-				$this->set($key, $new);
47
-				$this->remove($key . '_lock');
48
-				return true;
49
-			} else {
50
-				$this->remove($key . '_lock');
51
-				return false;
52
-			}
53
-		} else {
54
-			return false;
55
-		}
56
-	}
34
+    /**
35
+     * Compare and set
36
+     *
37
+     * @param string $key
38
+     * @param mixed $old
39
+     * @param mixed $new
40
+     * @return bool
41
+     */
42
+    public function cas($key, $old, $new) {
43
+        //no native cas, emulate with locking
44
+        if ($this->add($key . '_lock', true)) {
45
+            if ($this->get($key) === $old) {
46
+                $this->set($key, $new);
47
+                $this->remove($key . '_lock');
48
+                return true;
49
+            } else {
50
+                $this->remove($key . '_lock');
51
+                return false;
52
+            }
53
+        } else {
54
+            return false;
55
+        }
56
+    }
57 57
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -41,13 +41,13 @@
 block discarded – undo
41 41
 	 */
42 42
 	public function cas($key, $old, $new) {
43 43
 		//no native cas, emulate with locking
44
-		if ($this->add($key . '_lock', true)) {
44
+		if ($this->add($key.'_lock', true)) {
45 45
 			if ($this->get($key) === $old) {
46 46
 				$this->set($key, $new);
47
-				$this->remove($key . '_lock');
47
+				$this->remove($key.'_lock');
48 48
 				return true;
49 49
 			} else {
50
-				$this->remove($key . '_lock');
50
+				$this->remove($key.'_lock');
51 51
 				return false;
52 52
 			}
53 53
 		} else {
Please login to merge, or discard this patch.
lib/private/Memcache/CADTrait.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -23,32 +23,32 @@
 block discarded – undo
23 23
 namespace OC\Memcache;
24 24
 
25 25
 trait CADTrait {
26
-	abstract public function get($key);
26
+    abstract public function get($key);
27 27
 
28
-	abstract public function remove($key);
28
+    abstract public function remove($key);
29 29
 
30
-	abstract public function add($key, $value, $ttl = 0);
30
+    abstract public function add($key, $value, $ttl = 0);
31 31
 
32
-	/**
33
-	 * Compare and delete
34
-	 *
35
-	 * @param string $key
36
-	 * @param mixed $old
37
-	 * @return bool
38
-	 */
39
-	public function cad($key, $old) {
40
-		//no native cas, emulate with locking
41
-		if ($this->add($key . '_lock', true)) {
42
-			if ($this->get($key) === $old) {
43
-				$this->remove($key);
44
-				$this->remove($key . '_lock');
45
-				return true;
46
-			} else {
47
-				$this->remove($key . '_lock');
48
-				return false;
49
-			}
50
-		} else {
51
-			return false;
52
-		}
53
-	}
32
+    /**
33
+     * Compare and delete
34
+     *
35
+     * @param string $key
36
+     * @param mixed $old
37
+     * @return bool
38
+     */
39
+    public function cad($key, $old) {
40
+        //no native cas, emulate with locking
41
+        if ($this->add($key . '_lock', true)) {
42
+            if ($this->get($key) === $old) {
43
+                $this->remove($key);
44
+                $this->remove($key . '_lock');
45
+                return true;
46
+            } else {
47
+                $this->remove($key . '_lock');
48
+                return false;
49
+            }
50
+        } else {
51
+            return false;
52
+        }
53
+    }
54 54
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -38,13 +38,13 @@
 block discarded – undo
38 38
 	 */
39 39
 	public function cad($key, $old) {
40 40
 		//no native cas, emulate with locking
41
-		if ($this->add($key . '_lock', true)) {
41
+		if ($this->add($key.'_lock', true)) {
42 42
 			if ($this->get($key) === $old) {
43 43
 				$this->remove($key);
44
-				$this->remove($key . '_lock');
44
+				$this->remove($key.'_lock');
45 45
 				return true;
46 46
 			} else {
47
-				$this->remove($key . '_lock');
47
+				$this->remove($key.'_lock');
48 48
 				return false;
49 49
 			}
50 50
 		} else {
Please login to merge, or discard this patch.
lib/private/Files/Config/UserMountCacheListener.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -29,21 +29,21 @@
 block discarded – undo
29 29
  * Listen to hooks and update the mount cache as needed
30 30
  */
31 31
 class UserMountCacheListener {
32
-	/**
33
-	 * @var IUserMountCache
34
-	 */
35
-	private $userMountCache;
32
+    /**
33
+     * @var IUserMountCache
34
+     */
35
+    private $userMountCache;
36 36
 
37
-	/**
38
-	 * UserMountCacheListener constructor.
39
-	 *
40
-	 * @param IUserMountCache $userMountCache
41
-	 */
42
-	public function __construct(IUserMountCache $userMountCache) {
43
-		$this->userMountCache = $userMountCache;
44
-	}
37
+    /**
38
+     * UserMountCacheListener constructor.
39
+     *
40
+     * @param IUserMountCache $userMountCache
41
+     */
42
+    public function __construct(IUserMountCache $userMountCache) {
43
+        $this->userMountCache = $userMountCache;
44
+    }
45 45
 
46
-	public function listen(Manager $manager) {
47
-		$manager->listen('\OC\User', 'postDelete', [$this->userMountCache, 'removeUserMounts']);
48
-	}
46
+    public function listen(Manager $manager) {
47
+        $manager->listen('\OC\User', 'postDelete', [$this->userMountCache, 'removeUserMounts']);
48
+    }
49 49
 }
Please login to merge, or discard this patch.
lib/private/Files/Storage/Wrapper/Encoding.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 				// no point in continuing if the section was not found, use original path
81 81
 				return $fullPath;
82 82
 			}
83
-			$path = $convertedPath . '/';
83
+			$path = $convertedPath.'/';
84 84
 		}
85 85
 		$path = rtrim($path, '/');
86 86
 		return $path;
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 * @return string|null original or converted path, or null if none of the forms was found
97 97
 	 */
98 98
 	private function findPathToUseLastSection($basePath, $lastSection) {
99
-		$fullPath = $basePath . $lastSection;
99
+		$fullPath = $basePath.$lastSection;
100 100
 		if ($lastSection === '' || $this->isAscii($lastSection) || $this->storage->file_exists($fullPath)) {
101 101
 			$this->namesCache[$fullPath] = $fullPath;
102 102
 			return $fullPath;
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 		} else {
109 109
 			$otherFormPath = \Normalizer::normalize($lastSection, \Normalizer::FORM_C);
110 110
 		}
111
-		$otherFullPath = $basePath . $otherFormPath;
111
+		$otherFullPath = $basePath.$otherFormPath;
112 112
 		if ($this->storage->file_exists($otherFullPath)) {
113 113
 			$this->namesCache[$fullPath] = $otherFullPath;
114 114
 			return $otherFullPath;
Please login to merge, or discard this patch.
Indentation   +505 added lines, -505 removed lines patch added patch discarded remove patch
@@ -41,509 +41,509 @@
 block discarded – undo
41 41
  */
42 42
 class Encoding extends Wrapper {
43 43
 
44
-	/**
45
-	 * @var ICache
46
-	 */
47
-	private $namesCache;
48
-
49
-	/**
50
-	 * @param array $parameters
51
-	 */
52
-	public function __construct($parameters) {
53
-		$this->storage = $parameters['storage'];
54
-		$this->namesCache = new CappedMemoryCache();
55
-	}
56
-
57
-	/**
58
-	 * Returns whether the given string is only made of ASCII characters
59
-	 *
60
-	 * @param string $str string
61
-	 *
62
-	 * @return bool true if the string is all ASCII, false otherwise
63
-	 */
64
-	private function isAscii($str) {
65
-		return !preg_match('/[\\x80-\\xff]+/', $str);
66
-	}
67
-
68
-	/**
69
-	 * Checks whether the given path exists in NFC or NFD form after checking
70
-	 * each form for each path section and returns the correct form.
71
-	 * If no existing path found, returns the path as it was given.
72
-	 *
73
-	 * @param string $fullPath path to check
74
-	 *
75
-	 * @return string original or converted path
76
-	 */
77
-	private function findPathToUse($fullPath) {
78
-		$cachedPath = $this->namesCache[$fullPath];
79
-		if ($cachedPath !== null) {
80
-			return $cachedPath;
81
-		}
82
-
83
-		$sections = explode('/', $fullPath);
84
-		$path = '';
85
-		foreach ($sections as $section) {
86
-			$convertedPath = $this->findPathToUseLastSection($path, $section);
87
-			if ($convertedPath === null) {
88
-				// no point in continuing if the section was not found, use original path
89
-				return $fullPath;
90
-			}
91
-			$path = $convertedPath . '/';
92
-		}
93
-		$path = rtrim($path, '/');
94
-		return $path;
95
-	}
96
-
97
-	/**
98
-	 * Checks whether the last path section of the given path exists in NFC or NFD form
99
-	 * and returns the correct form. If no existing path found, returns null.
100
-	 *
101
-	 * @param string $basePath base path to check
102
-	 * @param string $lastSection last section of the path to check for NFD/NFC variations
103
-	 *
104
-	 * @return string|null original or converted path, or null if none of the forms was found
105
-	 */
106
-	private function findPathToUseLastSection($basePath, $lastSection) {
107
-		$fullPath = $basePath . $lastSection;
108
-		if ($lastSection === '' || $this->isAscii($lastSection) || $this->storage->file_exists($fullPath)) {
109
-			$this->namesCache[$fullPath] = $fullPath;
110
-			return $fullPath;
111
-		}
112
-
113
-		// swap encoding
114
-		if (\Normalizer::isNormalized($lastSection, \Normalizer::FORM_C)) {
115
-			$otherFormPath = \Normalizer::normalize($lastSection, \Normalizer::FORM_D);
116
-		} else {
117
-			$otherFormPath = \Normalizer::normalize($lastSection, \Normalizer::FORM_C);
118
-		}
119
-		$otherFullPath = $basePath . $otherFormPath;
120
-		if ($this->storage->file_exists($otherFullPath)) {
121
-			$this->namesCache[$fullPath] = $otherFullPath;
122
-			return $otherFullPath;
123
-		}
124
-
125
-		// return original path, file did not exist at all
126
-		$this->namesCache[$fullPath] = $fullPath;
127
-		return null;
128
-	}
129
-
130
-	/**
131
-	 * see https://www.php.net/manual/en/function.mkdir.php
132
-	 *
133
-	 * @param string $path
134
-	 * @return bool
135
-	 */
136
-	public function mkdir($path) {
137
-		// note: no conversion here, method should not be called with non-NFC names!
138
-		$result = $this->storage->mkdir($path);
139
-		if ($result) {
140
-			$this->namesCache[$path] = $path;
141
-		}
142
-		return $result;
143
-	}
144
-
145
-	/**
146
-	 * see https://www.php.net/manual/en/function.rmdir.php
147
-	 *
148
-	 * @param string $path
149
-	 * @return bool
150
-	 */
151
-	public function rmdir($path) {
152
-		$result = $this->storage->rmdir($this->findPathToUse($path));
153
-		if ($result) {
154
-			unset($this->namesCache[$path]);
155
-		}
156
-		return $result;
157
-	}
158
-
159
-	/**
160
-	 * see https://www.php.net/manual/en/function.opendir.php
161
-	 *
162
-	 * @param string $path
163
-	 * @return resource|bool
164
-	 */
165
-	public function opendir($path) {
166
-		$handle = $this->storage->opendir($this->findPathToUse($path));
167
-		return EncodingDirectoryWrapper::wrap($handle);
168
-	}
169
-
170
-	/**
171
-	 * see https://www.php.net/manual/en/function.is_dir.php
172
-	 *
173
-	 * @param string $path
174
-	 * @return bool
175
-	 */
176
-	public function is_dir($path) {
177
-		return $this->storage->is_dir($this->findPathToUse($path));
178
-	}
179
-
180
-	/**
181
-	 * see https://www.php.net/manual/en/function.is_file.php
182
-	 *
183
-	 * @param string $path
184
-	 * @return bool
185
-	 */
186
-	public function is_file($path) {
187
-		return $this->storage->is_file($this->findPathToUse($path));
188
-	}
189
-
190
-	/**
191
-	 * see https://www.php.net/manual/en/function.stat.php
192
-	 * only the following keys are required in the result: size and mtime
193
-	 *
194
-	 * @param string $path
195
-	 * @return array|bool
196
-	 */
197
-	public function stat($path) {
198
-		return $this->storage->stat($this->findPathToUse($path));
199
-	}
200
-
201
-	/**
202
-	 * see https://www.php.net/manual/en/function.filetype.php
203
-	 *
204
-	 * @param string $path
205
-	 * @return string|bool
206
-	 */
207
-	public function filetype($path) {
208
-		return $this->storage->filetype($this->findPathToUse($path));
209
-	}
210
-
211
-	/**
212
-	 * see https://www.php.net/manual/en/function.filesize.php
213
-	 * The result for filesize when called on a folder is required to be 0
214
-	 *
215
-	 * @param string $path
216
-	 * @return int|bool
217
-	 */
218
-	public function filesize($path) {
219
-		return $this->storage->filesize($this->findPathToUse($path));
220
-	}
221
-
222
-	/**
223
-	 * check if a file can be created in $path
224
-	 *
225
-	 * @param string $path
226
-	 * @return bool
227
-	 */
228
-	public function isCreatable($path) {
229
-		return $this->storage->isCreatable($this->findPathToUse($path));
230
-	}
231
-
232
-	/**
233
-	 * check if a file can be read
234
-	 *
235
-	 * @param string $path
236
-	 * @return bool
237
-	 */
238
-	public function isReadable($path) {
239
-		return $this->storage->isReadable($this->findPathToUse($path));
240
-	}
241
-
242
-	/**
243
-	 * check if a file can be written to
244
-	 *
245
-	 * @param string $path
246
-	 * @return bool
247
-	 */
248
-	public function isUpdatable($path) {
249
-		return $this->storage->isUpdatable($this->findPathToUse($path));
250
-	}
251
-
252
-	/**
253
-	 * check if a file can be deleted
254
-	 *
255
-	 * @param string $path
256
-	 * @return bool
257
-	 */
258
-	public function isDeletable($path) {
259
-		return $this->storage->isDeletable($this->findPathToUse($path));
260
-	}
261
-
262
-	/**
263
-	 * check if a file can be shared
264
-	 *
265
-	 * @param string $path
266
-	 * @return bool
267
-	 */
268
-	public function isSharable($path) {
269
-		return $this->storage->isSharable($this->findPathToUse($path));
270
-	}
271
-
272
-	/**
273
-	 * get the full permissions of a path.
274
-	 * Should return a combination of the PERMISSION_ constants defined in lib/public/constants.php
275
-	 *
276
-	 * @param string $path
277
-	 * @return int
278
-	 */
279
-	public function getPermissions($path) {
280
-		return $this->storage->getPermissions($this->findPathToUse($path));
281
-	}
282
-
283
-	/**
284
-	 * see https://www.php.net/manual/en/function.file_exists.php
285
-	 *
286
-	 * @param string $path
287
-	 * @return bool
288
-	 */
289
-	public function file_exists($path) {
290
-		return $this->storage->file_exists($this->findPathToUse($path));
291
-	}
292
-
293
-	/**
294
-	 * see https://www.php.net/manual/en/function.filemtime.php
295
-	 *
296
-	 * @param string $path
297
-	 * @return int|bool
298
-	 */
299
-	public function filemtime($path) {
300
-		return $this->storage->filemtime($this->findPathToUse($path));
301
-	}
302
-
303
-	/**
304
-	 * see https://www.php.net/manual/en/function.file_get_contents.php
305
-	 *
306
-	 * @param string $path
307
-	 * @return string|bool
308
-	 */
309
-	public function file_get_contents($path) {
310
-		return $this->storage->file_get_contents($this->findPathToUse($path));
311
-	}
312
-
313
-	/**
314
-	 * see https://www.php.net/manual/en/function.file_put_contents.php
315
-	 *
316
-	 * @param string $path
317
-	 * @param mixed $data
318
-	 * @return int|false
319
-	 */
320
-	public function file_put_contents($path, $data) {
321
-		return $this->storage->file_put_contents($this->findPathToUse($path), $data);
322
-	}
323
-
324
-	/**
325
-	 * see https://www.php.net/manual/en/function.unlink.php
326
-	 *
327
-	 * @param string $path
328
-	 * @return bool
329
-	 */
330
-	public function unlink($path) {
331
-		$result = $this->storage->unlink($this->findPathToUse($path));
332
-		if ($result) {
333
-			unset($this->namesCache[$path]);
334
-		}
335
-		return $result;
336
-	}
337
-
338
-	/**
339
-	 * see https://www.php.net/manual/en/function.rename.php
340
-	 *
341
-	 * @param string $source
342
-	 * @param string $target
343
-	 * @return bool
344
-	 */
345
-	public function rename($source, $target) {
346
-		// second name always NFC
347
-		return $this->storage->rename($this->findPathToUse($source), $this->findPathToUse($target));
348
-	}
349
-
350
-	/**
351
-	 * see https://www.php.net/manual/en/function.copy.php
352
-	 *
353
-	 * @param string $source
354
-	 * @param string $target
355
-	 * @return bool
356
-	 */
357
-	public function copy($source, $target) {
358
-		return $this->storage->copy($this->findPathToUse($source), $this->findPathToUse($target));
359
-	}
360
-
361
-	/**
362
-	 * see https://www.php.net/manual/en/function.fopen.php
363
-	 *
364
-	 * @param string $path
365
-	 * @param string $mode
366
-	 * @return resource|bool
367
-	 */
368
-	public function fopen($path, $mode) {
369
-		$result = $this->storage->fopen($this->findPathToUse($path), $mode);
370
-		if ($result && $mode !== 'r' && $mode !== 'rb') {
371
-			unset($this->namesCache[$path]);
372
-		}
373
-		return $result;
374
-	}
375
-
376
-	/**
377
-	 * get the mimetype for a file or folder
378
-	 * The mimetype for a folder is required to be "httpd/unix-directory"
379
-	 *
380
-	 * @param string $path
381
-	 * @return string|bool
382
-	 */
383
-	public function getMimeType($path) {
384
-		return $this->storage->getMimeType($this->findPathToUse($path));
385
-	}
386
-
387
-	/**
388
-	 * see https://www.php.net/manual/en/function.hash.php
389
-	 *
390
-	 * @param string $type
391
-	 * @param string $path
392
-	 * @param bool $raw
393
-	 * @return string|bool
394
-	 */
395
-	public function hash($type, $path, $raw = false) {
396
-		return $this->storage->hash($type, $this->findPathToUse($path), $raw);
397
-	}
398
-
399
-	/**
400
-	 * see https://www.php.net/manual/en/function.free_space.php
401
-	 *
402
-	 * @param string $path
403
-	 * @return int|bool
404
-	 */
405
-	public function free_space($path) {
406
-		return $this->storage->free_space($this->findPathToUse($path));
407
-	}
408
-
409
-	/**
410
-	 * search for occurrences of $query in file names
411
-	 *
412
-	 * @param string $query
413
-	 * @return array|bool
414
-	 */
415
-	public function search($query) {
416
-		return $this->storage->search($query);
417
-	}
418
-
419
-	/**
420
-	 * see https://www.php.net/manual/en/function.touch.php
421
-	 * If the backend does not support the operation, false should be returned
422
-	 *
423
-	 * @param string $path
424
-	 * @param int $mtime
425
-	 * @return bool
426
-	 */
427
-	public function touch($path, $mtime = null) {
428
-		return $this->storage->touch($this->findPathToUse($path), $mtime);
429
-	}
430
-
431
-	/**
432
-	 * get the path to a local version of the file.
433
-	 * The local version of the file can be temporary and doesn't have to be persistent across requests
434
-	 *
435
-	 * @param string $path
436
-	 * @return string|bool
437
-	 */
438
-	public function getLocalFile($path) {
439
-		return $this->storage->getLocalFile($this->findPathToUse($path));
440
-	}
441
-
442
-	/**
443
-	 * check if a file or folder has been updated since $time
444
-	 *
445
-	 * @param string $path
446
-	 * @param int $time
447
-	 * @return bool
448
-	 *
449
-	 * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed.
450
-	 * returning true for other changes in the folder is optional
451
-	 */
452
-	public function hasUpdated($path, $time) {
453
-		return $this->storage->hasUpdated($this->findPathToUse($path), $time);
454
-	}
455
-
456
-	/**
457
-	 * get a cache instance for the storage
458
-	 *
459
-	 * @param string $path
460
-	 * @param \OC\Files\Storage\Storage (optional) the storage to pass to the cache
461
-	 * @return \OC\Files\Cache\Cache
462
-	 */
463
-	public function getCache($path = '', $storage = null) {
464
-		if (!$storage) {
465
-			$storage = $this;
466
-		}
467
-		return $this->storage->getCache($this->findPathToUse($path), $storage);
468
-	}
469
-
470
-	/**
471
-	 * get a scanner instance for the storage
472
-	 *
473
-	 * @param string $path
474
-	 * @param \OC\Files\Storage\Storage (optional) the storage to pass to the scanner
475
-	 * @return \OC\Files\Cache\Scanner
476
-	 */
477
-	public function getScanner($path = '', $storage = null) {
478
-		if (!$storage) {
479
-			$storage = $this;
480
-		}
481
-		return $this->storage->getScanner($this->findPathToUse($path), $storage);
482
-	}
483
-
484
-	/**
485
-	 * get the ETag for a file or folder
486
-	 *
487
-	 * @param string $path
488
-	 * @return string|bool
489
-	 */
490
-	public function getETag($path) {
491
-		return $this->storage->getETag($this->findPathToUse($path));
492
-	}
493
-
494
-	/**
495
-	 * @param IStorage $sourceStorage
496
-	 * @param string $sourceInternalPath
497
-	 * @param string $targetInternalPath
498
-	 * @return bool
499
-	 */
500
-	public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
501
-		if ($sourceStorage === $this) {
502
-			return $this->copy($sourceInternalPath, $this->findPathToUse($targetInternalPath));
503
-		}
504
-
505
-		$result = $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $this->findPathToUse($targetInternalPath));
506
-		if ($result) {
507
-			unset($this->namesCache[$targetInternalPath]);
508
-		}
509
-		return $result;
510
-	}
511
-
512
-	/**
513
-	 * @param IStorage $sourceStorage
514
-	 * @param string $sourceInternalPath
515
-	 * @param string $targetInternalPath
516
-	 * @return bool
517
-	 */
518
-	public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
519
-		if ($sourceStorage === $this) {
520
-			$result = $this->rename($sourceInternalPath, $this->findPathToUse($targetInternalPath));
521
-			if ($result) {
522
-				unset($this->namesCache[$sourceInternalPath]);
523
-				unset($this->namesCache[$targetInternalPath]);
524
-			}
525
-			return $result;
526
-		}
527
-
528
-		$result = $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $this->findPathToUse($targetInternalPath));
529
-		if ($result) {
530
-			unset($this->namesCache[$sourceInternalPath]);
531
-			unset($this->namesCache[$targetInternalPath]);
532
-		}
533
-		return $result;
534
-	}
535
-
536
-	public function getMetaData($path) {
537
-		$entry = $this->storage->getMetaData($this->findPathToUse($path));
538
-		$entry['name'] = trim(Filesystem::normalizePath($entry['name']), '/');
539
-		return $entry;
540
-	}
541
-
542
-	public function getDirectoryContent($directory): \Traversable {
543
-		$entries = $this->storage->getDirectoryContent($this->findPathToUse($directory));
544
-		foreach ($entries as $entry) {
545
-			$entry['name'] = trim(Filesystem::normalizePath($entry['name']), '/');
546
-			yield $entry;
547
-		}
548
-	}
44
+    /**
45
+     * @var ICache
46
+     */
47
+    private $namesCache;
48
+
49
+    /**
50
+     * @param array $parameters
51
+     */
52
+    public function __construct($parameters) {
53
+        $this->storage = $parameters['storage'];
54
+        $this->namesCache = new CappedMemoryCache();
55
+    }
56
+
57
+    /**
58
+     * Returns whether the given string is only made of ASCII characters
59
+     *
60
+     * @param string $str string
61
+     *
62
+     * @return bool true if the string is all ASCII, false otherwise
63
+     */
64
+    private function isAscii($str) {
65
+        return !preg_match('/[\\x80-\\xff]+/', $str);
66
+    }
67
+
68
+    /**
69
+     * Checks whether the given path exists in NFC or NFD form after checking
70
+     * each form for each path section and returns the correct form.
71
+     * If no existing path found, returns the path as it was given.
72
+     *
73
+     * @param string $fullPath path to check
74
+     *
75
+     * @return string original or converted path
76
+     */
77
+    private function findPathToUse($fullPath) {
78
+        $cachedPath = $this->namesCache[$fullPath];
79
+        if ($cachedPath !== null) {
80
+            return $cachedPath;
81
+        }
82
+
83
+        $sections = explode('/', $fullPath);
84
+        $path = '';
85
+        foreach ($sections as $section) {
86
+            $convertedPath = $this->findPathToUseLastSection($path, $section);
87
+            if ($convertedPath === null) {
88
+                // no point in continuing if the section was not found, use original path
89
+                return $fullPath;
90
+            }
91
+            $path = $convertedPath . '/';
92
+        }
93
+        $path = rtrim($path, '/');
94
+        return $path;
95
+    }
96
+
97
+    /**
98
+     * Checks whether the last path section of the given path exists in NFC or NFD form
99
+     * and returns the correct form. If no existing path found, returns null.
100
+     *
101
+     * @param string $basePath base path to check
102
+     * @param string $lastSection last section of the path to check for NFD/NFC variations
103
+     *
104
+     * @return string|null original or converted path, or null if none of the forms was found
105
+     */
106
+    private function findPathToUseLastSection($basePath, $lastSection) {
107
+        $fullPath = $basePath . $lastSection;
108
+        if ($lastSection === '' || $this->isAscii($lastSection) || $this->storage->file_exists($fullPath)) {
109
+            $this->namesCache[$fullPath] = $fullPath;
110
+            return $fullPath;
111
+        }
112
+
113
+        // swap encoding
114
+        if (\Normalizer::isNormalized($lastSection, \Normalizer::FORM_C)) {
115
+            $otherFormPath = \Normalizer::normalize($lastSection, \Normalizer::FORM_D);
116
+        } else {
117
+            $otherFormPath = \Normalizer::normalize($lastSection, \Normalizer::FORM_C);
118
+        }
119
+        $otherFullPath = $basePath . $otherFormPath;
120
+        if ($this->storage->file_exists($otherFullPath)) {
121
+            $this->namesCache[$fullPath] = $otherFullPath;
122
+            return $otherFullPath;
123
+        }
124
+
125
+        // return original path, file did not exist at all
126
+        $this->namesCache[$fullPath] = $fullPath;
127
+        return null;
128
+    }
129
+
130
+    /**
131
+     * see https://www.php.net/manual/en/function.mkdir.php
132
+     *
133
+     * @param string $path
134
+     * @return bool
135
+     */
136
+    public function mkdir($path) {
137
+        // note: no conversion here, method should not be called with non-NFC names!
138
+        $result = $this->storage->mkdir($path);
139
+        if ($result) {
140
+            $this->namesCache[$path] = $path;
141
+        }
142
+        return $result;
143
+    }
144
+
145
+    /**
146
+     * see https://www.php.net/manual/en/function.rmdir.php
147
+     *
148
+     * @param string $path
149
+     * @return bool
150
+     */
151
+    public function rmdir($path) {
152
+        $result = $this->storage->rmdir($this->findPathToUse($path));
153
+        if ($result) {
154
+            unset($this->namesCache[$path]);
155
+        }
156
+        return $result;
157
+    }
158
+
159
+    /**
160
+     * see https://www.php.net/manual/en/function.opendir.php
161
+     *
162
+     * @param string $path
163
+     * @return resource|bool
164
+     */
165
+    public function opendir($path) {
166
+        $handle = $this->storage->opendir($this->findPathToUse($path));
167
+        return EncodingDirectoryWrapper::wrap($handle);
168
+    }
169
+
170
+    /**
171
+     * see https://www.php.net/manual/en/function.is_dir.php
172
+     *
173
+     * @param string $path
174
+     * @return bool
175
+     */
176
+    public function is_dir($path) {
177
+        return $this->storage->is_dir($this->findPathToUse($path));
178
+    }
179
+
180
+    /**
181
+     * see https://www.php.net/manual/en/function.is_file.php
182
+     *
183
+     * @param string $path
184
+     * @return bool
185
+     */
186
+    public function is_file($path) {
187
+        return $this->storage->is_file($this->findPathToUse($path));
188
+    }
189
+
190
+    /**
191
+     * see https://www.php.net/manual/en/function.stat.php
192
+     * only the following keys are required in the result: size and mtime
193
+     *
194
+     * @param string $path
195
+     * @return array|bool
196
+     */
197
+    public function stat($path) {
198
+        return $this->storage->stat($this->findPathToUse($path));
199
+    }
200
+
201
+    /**
202
+     * see https://www.php.net/manual/en/function.filetype.php
203
+     *
204
+     * @param string $path
205
+     * @return string|bool
206
+     */
207
+    public function filetype($path) {
208
+        return $this->storage->filetype($this->findPathToUse($path));
209
+    }
210
+
211
+    /**
212
+     * see https://www.php.net/manual/en/function.filesize.php
213
+     * The result for filesize when called on a folder is required to be 0
214
+     *
215
+     * @param string $path
216
+     * @return int|bool
217
+     */
218
+    public function filesize($path) {
219
+        return $this->storage->filesize($this->findPathToUse($path));
220
+    }
221
+
222
+    /**
223
+     * check if a file can be created in $path
224
+     *
225
+     * @param string $path
226
+     * @return bool
227
+     */
228
+    public function isCreatable($path) {
229
+        return $this->storage->isCreatable($this->findPathToUse($path));
230
+    }
231
+
232
+    /**
233
+     * check if a file can be read
234
+     *
235
+     * @param string $path
236
+     * @return bool
237
+     */
238
+    public function isReadable($path) {
239
+        return $this->storage->isReadable($this->findPathToUse($path));
240
+    }
241
+
242
+    /**
243
+     * check if a file can be written to
244
+     *
245
+     * @param string $path
246
+     * @return bool
247
+     */
248
+    public function isUpdatable($path) {
249
+        return $this->storage->isUpdatable($this->findPathToUse($path));
250
+    }
251
+
252
+    /**
253
+     * check if a file can be deleted
254
+     *
255
+     * @param string $path
256
+     * @return bool
257
+     */
258
+    public function isDeletable($path) {
259
+        return $this->storage->isDeletable($this->findPathToUse($path));
260
+    }
261
+
262
+    /**
263
+     * check if a file can be shared
264
+     *
265
+     * @param string $path
266
+     * @return bool
267
+     */
268
+    public function isSharable($path) {
269
+        return $this->storage->isSharable($this->findPathToUse($path));
270
+    }
271
+
272
+    /**
273
+     * get the full permissions of a path.
274
+     * Should return a combination of the PERMISSION_ constants defined in lib/public/constants.php
275
+     *
276
+     * @param string $path
277
+     * @return int
278
+     */
279
+    public function getPermissions($path) {
280
+        return $this->storage->getPermissions($this->findPathToUse($path));
281
+    }
282
+
283
+    /**
284
+     * see https://www.php.net/manual/en/function.file_exists.php
285
+     *
286
+     * @param string $path
287
+     * @return bool
288
+     */
289
+    public function file_exists($path) {
290
+        return $this->storage->file_exists($this->findPathToUse($path));
291
+    }
292
+
293
+    /**
294
+     * see https://www.php.net/manual/en/function.filemtime.php
295
+     *
296
+     * @param string $path
297
+     * @return int|bool
298
+     */
299
+    public function filemtime($path) {
300
+        return $this->storage->filemtime($this->findPathToUse($path));
301
+    }
302
+
303
+    /**
304
+     * see https://www.php.net/manual/en/function.file_get_contents.php
305
+     *
306
+     * @param string $path
307
+     * @return string|bool
308
+     */
309
+    public function file_get_contents($path) {
310
+        return $this->storage->file_get_contents($this->findPathToUse($path));
311
+    }
312
+
313
+    /**
314
+     * see https://www.php.net/manual/en/function.file_put_contents.php
315
+     *
316
+     * @param string $path
317
+     * @param mixed $data
318
+     * @return int|false
319
+     */
320
+    public function file_put_contents($path, $data) {
321
+        return $this->storage->file_put_contents($this->findPathToUse($path), $data);
322
+    }
323
+
324
+    /**
325
+     * see https://www.php.net/manual/en/function.unlink.php
326
+     *
327
+     * @param string $path
328
+     * @return bool
329
+     */
330
+    public function unlink($path) {
331
+        $result = $this->storage->unlink($this->findPathToUse($path));
332
+        if ($result) {
333
+            unset($this->namesCache[$path]);
334
+        }
335
+        return $result;
336
+    }
337
+
338
+    /**
339
+     * see https://www.php.net/manual/en/function.rename.php
340
+     *
341
+     * @param string $source
342
+     * @param string $target
343
+     * @return bool
344
+     */
345
+    public function rename($source, $target) {
346
+        // second name always NFC
347
+        return $this->storage->rename($this->findPathToUse($source), $this->findPathToUse($target));
348
+    }
349
+
350
+    /**
351
+     * see https://www.php.net/manual/en/function.copy.php
352
+     *
353
+     * @param string $source
354
+     * @param string $target
355
+     * @return bool
356
+     */
357
+    public function copy($source, $target) {
358
+        return $this->storage->copy($this->findPathToUse($source), $this->findPathToUse($target));
359
+    }
360
+
361
+    /**
362
+     * see https://www.php.net/manual/en/function.fopen.php
363
+     *
364
+     * @param string $path
365
+     * @param string $mode
366
+     * @return resource|bool
367
+     */
368
+    public function fopen($path, $mode) {
369
+        $result = $this->storage->fopen($this->findPathToUse($path), $mode);
370
+        if ($result && $mode !== 'r' && $mode !== 'rb') {
371
+            unset($this->namesCache[$path]);
372
+        }
373
+        return $result;
374
+    }
375
+
376
+    /**
377
+     * get the mimetype for a file or folder
378
+     * The mimetype for a folder is required to be "httpd/unix-directory"
379
+     *
380
+     * @param string $path
381
+     * @return string|bool
382
+     */
383
+    public function getMimeType($path) {
384
+        return $this->storage->getMimeType($this->findPathToUse($path));
385
+    }
386
+
387
+    /**
388
+     * see https://www.php.net/manual/en/function.hash.php
389
+     *
390
+     * @param string $type
391
+     * @param string $path
392
+     * @param bool $raw
393
+     * @return string|bool
394
+     */
395
+    public function hash($type, $path, $raw = false) {
396
+        return $this->storage->hash($type, $this->findPathToUse($path), $raw);
397
+    }
398
+
399
+    /**
400
+     * see https://www.php.net/manual/en/function.free_space.php
401
+     *
402
+     * @param string $path
403
+     * @return int|bool
404
+     */
405
+    public function free_space($path) {
406
+        return $this->storage->free_space($this->findPathToUse($path));
407
+    }
408
+
409
+    /**
410
+     * search for occurrences of $query in file names
411
+     *
412
+     * @param string $query
413
+     * @return array|bool
414
+     */
415
+    public function search($query) {
416
+        return $this->storage->search($query);
417
+    }
418
+
419
+    /**
420
+     * see https://www.php.net/manual/en/function.touch.php
421
+     * If the backend does not support the operation, false should be returned
422
+     *
423
+     * @param string $path
424
+     * @param int $mtime
425
+     * @return bool
426
+     */
427
+    public function touch($path, $mtime = null) {
428
+        return $this->storage->touch($this->findPathToUse($path), $mtime);
429
+    }
430
+
431
+    /**
432
+     * get the path to a local version of the file.
433
+     * The local version of the file can be temporary and doesn't have to be persistent across requests
434
+     *
435
+     * @param string $path
436
+     * @return string|bool
437
+     */
438
+    public function getLocalFile($path) {
439
+        return $this->storage->getLocalFile($this->findPathToUse($path));
440
+    }
441
+
442
+    /**
443
+     * check if a file or folder has been updated since $time
444
+     *
445
+     * @param string $path
446
+     * @param int $time
447
+     * @return bool
448
+     *
449
+     * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed.
450
+     * returning true for other changes in the folder is optional
451
+     */
452
+    public function hasUpdated($path, $time) {
453
+        return $this->storage->hasUpdated($this->findPathToUse($path), $time);
454
+    }
455
+
456
+    /**
457
+     * get a cache instance for the storage
458
+     *
459
+     * @param string $path
460
+     * @param \OC\Files\Storage\Storage (optional) the storage to pass to the cache
461
+     * @return \OC\Files\Cache\Cache
462
+     */
463
+    public function getCache($path = '', $storage = null) {
464
+        if (!$storage) {
465
+            $storage = $this;
466
+        }
467
+        return $this->storage->getCache($this->findPathToUse($path), $storage);
468
+    }
469
+
470
+    /**
471
+     * get a scanner instance for the storage
472
+     *
473
+     * @param string $path
474
+     * @param \OC\Files\Storage\Storage (optional) the storage to pass to the scanner
475
+     * @return \OC\Files\Cache\Scanner
476
+     */
477
+    public function getScanner($path = '', $storage = null) {
478
+        if (!$storage) {
479
+            $storage = $this;
480
+        }
481
+        return $this->storage->getScanner($this->findPathToUse($path), $storage);
482
+    }
483
+
484
+    /**
485
+     * get the ETag for a file or folder
486
+     *
487
+     * @param string $path
488
+     * @return string|bool
489
+     */
490
+    public function getETag($path) {
491
+        return $this->storage->getETag($this->findPathToUse($path));
492
+    }
493
+
494
+    /**
495
+     * @param IStorage $sourceStorage
496
+     * @param string $sourceInternalPath
497
+     * @param string $targetInternalPath
498
+     * @return bool
499
+     */
500
+    public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
501
+        if ($sourceStorage === $this) {
502
+            return $this->copy($sourceInternalPath, $this->findPathToUse($targetInternalPath));
503
+        }
504
+
505
+        $result = $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $this->findPathToUse($targetInternalPath));
506
+        if ($result) {
507
+            unset($this->namesCache[$targetInternalPath]);
508
+        }
509
+        return $result;
510
+    }
511
+
512
+    /**
513
+     * @param IStorage $sourceStorage
514
+     * @param string $sourceInternalPath
515
+     * @param string $targetInternalPath
516
+     * @return bool
517
+     */
518
+    public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
519
+        if ($sourceStorage === $this) {
520
+            $result = $this->rename($sourceInternalPath, $this->findPathToUse($targetInternalPath));
521
+            if ($result) {
522
+                unset($this->namesCache[$sourceInternalPath]);
523
+                unset($this->namesCache[$targetInternalPath]);
524
+            }
525
+            return $result;
526
+        }
527
+
528
+        $result = $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $this->findPathToUse($targetInternalPath));
529
+        if ($result) {
530
+            unset($this->namesCache[$sourceInternalPath]);
531
+            unset($this->namesCache[$targetInternalPath]);
532
+        }
533
+        return $result;
534
+    }
535
+
536
+    public function getMetaData($path) {
537
+        $entry = $this->storage->getMetaData($this->findPathToUse($path));
538
+        $entry['name'] = trim(Filesystem::normalizePath($entry['name']), '/');
539
+        return $entry;
540
+    }
541
+
542
+    public function getDirectoryContent($directory): \Traversable {
543
+        $entries = $this->storage->getDirectoryContent($this->findPathToUse($directory));
544
+        foreach ($entries as $entry) {
545
+            $entry['name'] = trim(Filesystem::normalizePath($entry['name']), '/');
546
+            yield $entry;
547
+        }
548
+    }
549 549
 }
Please login to merge, or discard this patch.
lib/private/Files/Storage/LocalTempFileTrait.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -37,45 +37,45 @@
 block discarded – undo
37 37
  */
38 38
 trait LocalTempFileTrait {
39 39
 
40
-	/** @var string[] */
41
-	protected $cachedFiles = [];
40
+    /** @var string[] */
41
+    protected $cachedFiles = [];
42 42
 
43
-	/**
44
-	 * @param string $path
45
-	 * @return string
46
-	 */
47
-	protected function getCachedFile($path) {
48
-		if (!isset($this->cachedFiles[$path])) {
49
-			$this->cachedFiles[$path] = $this->toTmpFile($path);
50
-		}
51
-		return $this->cachedFiles[$path];
52
-	}
43
+    /**
44
+     * @param string $path
45
+     * @return string
46
+     */
47
+    protected function getCachedFile($path) {
48
+        if (!isset($this->cachedFiles[$path])) {
49
+            $this->cachedFiles[$path] = $this->toTmpFile($path);
50
+        }
51
+        return $this->cachedFiles[$path];
52
+    }
53 53
 
54
-	/**
55
-	 * @param string $path
56
-	 */
57
-	protected function removeCachedFile($path) {
58
-		unset($this->cachedFiles[$path]);
59
-	}
54
+    /**
55
+     * @param string $path
56
+     */
57
+    protected function removeCachedFile($path) {
58
+        unset($this->cachedFiles[$path]);
59
+    }
60 60
 
61
-	/**
62
-	 * @param string $path
63
-	 * @return string
64
-	 */
65
-	protected function toTmpFile($path) { //no longer in the storage api, still useful here
66
-		$source = $this->fopen($path, 'r');
67
-		if (!$source) {
68
-			return false;
69
-		}
70
-		if ($pos = strrpos($path, '.')) {
71
-			$extension = substr($path, $pos);
72
-		} else {
73
-			$extension = '';
74
-		}
75
-		$tmpFile = \OC::$server->getTempManager()->getTemporaryFile($extension);
76
-		$target = fopen($tmpFile, 'w');
77
-		\OC_Helper::streamCopy($source, $target);
78
-		fclose($target);
79
-		return $tmpFile;
80
-	}
61
+    /**
62
+     * @param string $path
63
+     * @return string
64
+     */
65
+    protected function toTmpFile($path) { //no longer in the storage api, still useful here
66
+        $source = $this->fopen($path, 'r');
67
+        if (!$source) {
68
+            return false;
69
+        }
70
+        if ($pos = strrpos($path, '.')) {
71
+            $extension = substr($path, $pos);
72
+        } else {
73
+            $extension = '';
74
+        }
75
+        $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($extension);
76
+        $target = fopen($tmpFile, 'w');
77
+        \OC_Helper::streamCopy($source, $target);
78
+        fclose($target);
79
+        return $tmpFile;
80
+    }
81 81
 }
Please login to merge, or discard this patch.
lib/private/Files/Storage/StorageFactory.php 2 patches
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -29,80 +29,80 @@
 block discarded – undo
29 29
 use OCP\Files\Storage\IStorageFactory;
30 30
 
31 31
 class StorageFactory implements IStorageFactory {
32
-	/**
33
-	 * @var array[] [$name=>['priority'=>$priority, 'wrapper'=>$callable] $storageWrappers
34
-	 */
35
-	private $storageWrappers = [];
32
+    /**
33
+     * @var array[] [$name=>['priority'=>$priority, 'wrapper'=>$callable] $storageWrappers
34
+     */
35
+    private $storageWrappers = [];
36 36
 
37
-	/**
38
-	 * allow modifier storage behaviour by adding wrappers around storages
39
-	 *
40
-	 * $callback should be a function of type (string $mountPoint, Storage $storage) => Storage
41
-	 *
42
-	 * @param string $wrapperName name of the wrapper
43
-	 * @param callable $callback callback
44
-	 * @param int $priority wrappers with the lower priority are applied last (meaning they get called first)
45
-	 * @param \OCP\Files\Mount\IMountPoint[] $existingMounts existing mount points to apply the wrapper to
46
-	 * @return bool true if the wrapper was added, false if there was already a wrapper with this
47
-	 * name registered
48
-	 */
49
-	public function addStorageWrapper($wrapperName, $callback, $priority = 50, $existingMounts = []) {
50
-		if (isset($this->storageWrappers[$wrapperName])) {
51
-			return false;
52
-		}
37
+    /**
38
+     * allow modifier storage behaviour by adding wrappers around storages
39
+     *
40
+     * $callback should be a function of type (string $mountPoint, Storage $storage) => Storage
41
+     *
42
+     * @param string $wrapperName name of the wrapper
43
+     * @param callable $callback callback
44
+     * @param int $priority wrappers with the lower priority are applied last (meaning they get called first)
45
+     * @param \OCP\Files\Mount\IMountPoint[] $existingMounts existing mount points to apply the wrapper to
46
+     * @return bool true if the wrapper was added, false if there was already a wrapper with this
47
+     * name registered
48
+     */
49
+    public function addStorageWrapper($wrapperName, $callback, $priority = 50, $existingMounts = []) {
50
+        if (isset($this->storageWrappers[$wrapperName])) {
51
+            return false;
52
+        }
53 53
 
54
-		// apply to existing mounts before registering it to prevent applying it double in MountPoint::createStorage
55
-		foreach ($existingMounts as $mount) {
56
-			$mount->wrapStorage($callback);
57
-		}
54
+        // apply to existing mounts before registering it to prevent applying it double in MountPoint::createStorage
55
+        foreach ($existingMounts as $mount) {
56
+            $mount->wrapStorage($callback);
57
+        }
58 58
 
59
-		$this->storageWrappers[$wrapperName] = ['wrapper' => $callback, 'priority' => $priority];
60
-		return true;
61
-	}
59
+        $this->storageWrappers[$wrapperName] = ['wrapper' => $callback, 'priority' => $priority];
60
+        return true;
61
+    }
62 62
 
63
-	/**
64
-	 * Remove a storage wrapper by name.
65
-	 * Note: internal method only to be used for cleanup
66
-	 *
67
-	 * @param string $wrapperName name of the wrapper
68
-	 * @internal
69
-	 */
70
-	public function removeStorageWrapper($wrapperName) {
71
-		unset($this->storageWrappers[$wrapperName]);
72
-	}
63
+    /**
64
+     * Remove a storage wrapper by name.
65
+     * Note: internal method only to be used for cleanup
66
+     *
67
+     * @param string $wrapperName name of the wrapper
68
+     * @internal
69
+     */
70
+    public function removeStorageWrapper($wrapperName) {
71
+        unset($this->storageWrappers[$wrapperName]);
72
+    }
73 73
 
74
-	/**
75
-	 * Create an instance of a storage and apply the registered storage wrappers
76
-	 *
77
-	 * @param \OCP\Files\Mount\IMountPoint $mountPoint
78
-	 * @param string $class
79
-	 * @param array $arguments
80
-	 * @return \OCP\Files\Storage
81
-	 */
82
-	public function getInstance(IMountPoint $mountPoint, $class, $arguments) {
83
-		return $this->wrap($mountPoint, new $class($arguments));
84
-	}
74
+    /**
75
+     * Create an instance of a storage and apply the registered storage wrappers
76
+     *
77
+     * @param \OCP\Files\Mount\IMountPoint $mountPoint
78
+     * @param string $class
79
+     * @param array $arguments
80
+     * @return \OCP\Files\Storage
81
+     */
82
+    public function getInstance(IMountPoint $mountPoint, $class, $arguments) {
83
+        return $this->wrap($mountPoint, new $class($arguments));
84
+    }
85 85
 
86
-	/**
87
-	 * @param \OCP\Files\Mount\IMountPoint $mountPoint
88
-	 * @param \OCP\Files\Storage $storage
89
-	 * @return \OCP\Files\Storage
90
-	 */
91
-	public function wrap(IMountPoint $mountPoint, $storage) {
92
-		$wrappers = array_values($this->storageWrappers);
93
-		usort($wrappers, function ($a, $b) {
94
-			return $b['priority'] - $a['priority'];
95
-		});
96
-		/** @var callable[] $wrappers */
97
-		$wrappers = array_map(function ($wrapper) {
98
-			return $wrapper['wrapper'];
99
-		}, $wrappers);
100
-		foreach ($wrappers as $wrapper) {
101
-			$storage = $wrapper($mountPoint->getMountPoint(), $storage, $mountPoint);
102
-			if (!($storage instanceof \OCP\Files\Storage)) {
103
-				throw new \Exception('Invalid result from storage wrapper');
104
-			}
105
-		}
106
-		return $storage;
107
-	}
86
+    /**
87
+     * @param \OCP\Files\Mount\IMountPoint $mountPoint
88
+     * @param \OCP\Files\Storage $storage
89
+     * @return \OCP\Files\Storage
90
+     */
91
+    public function wrap(IMountPoint $mountPoint, $storage) {
92
+        $wrappers = array_values($this->storageWrappers);
93
+        usort($wrappers, function ($a, $b) {
94
+            return $b['priority'] - $a['priority'];
95
+        });
96
+        /** @var callable[] $wrappers */
97
+        $wrappers = array_map(function ($wrapper) {
98
+            return $wrapper['wrapper'];
99
+        }, $wrappers);
100
+        foreach ($wrappers as $wrapper) {
101
+            $storage = $wrapper($mountPoint->getMountPoint(), $storage, $mountPoint);
102
+            if (!($storage instanceof \OCP\Files\Storage)) {
103
+                throw new \Exception('Invalid result from storage wrapper');
104
+            }
105
+        }
106
+        return $storage;
107
+    }
108 108
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -90,11 +90,11 @@
 block discarded – undo
90 90
 	 */
91 91
 	public function wrap(IMountPoint $mountPoint, $storage) {
92 92
 		$wrappers = array_values($this->storageWrappers);
93
-		usort($wrappers, function ($a, $b) {
93
+		usort($wrappers, function($a, $b) {
94 94
 			return $b['priority'] - $a['priority'];
95 95
 		});
96 96
 		/** @var callable[] $wrappers */
97
-		$wrappers = array_map(function ($wrapper) {
97
+		$wrappers = array_map(function($wrapper) {
98 98
 			return $wrapper['wrapper'];
99 99
 		}, $wrappers);
100 100
 		foreach ($wrappers as $wrapper) {
Please login to merge, or discard this patch.
lib/private/Files/Storage/PolyFill/CopyDirectory.php 2 patches
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -25,81 +25,81 @@
 block discarded – undo
25 25
 namespace OC\Files\Storage\PolyFill;
26 26
 
27 27
 trait CopyDirectory {
28
-	/**
29
-	 * Check if a path is a directory
30
-	 *
31
-	 * @param string $path
32
-	 * @return bool
33
-	 */
34
-	abstract public function is_dir($path);
28
+    /**
29
+     * Check if a path is a directory
30
+     *
31
+     * @param string $path
32
+     * @return bool
33
+     */
34
+    abstract public function is_dir($path);
35 35
 
36
-	/**
37
-	 * Check if a file or folder exists
38
-	 *
39
-	 * @param string $path
40
-	 * @return bool
41
-	 */
42
-	abstract public function file_exists($path);
36
+    /**
37
+     * Check if a file or folder exists
38
+     *
39
+     * @param string $path
40
+     * @return bool
41
+     */
42
+    abstract public function file_exists($path);
43 43
 
44
-	/**
45
-	 * Delete a file or folder
46
-	 *
47
-	 * @param string $path
48
-	 * @return bool
49
-	 */
50
-	abstract public function unlink($path);
44
+    /**
45
+     * Delete a file or folder
46
+     *
47
+     * @param string $path
48
+     * @return bool
49
+     */
50
+    abstract public function unlink($path);
51 51
 
52
-	/**
53
-	 * Open a directory handle for a folder
54
-	 *
55
-	 * @param string $path
56
-	 * @return resource | bool
57
-	 */
58
-	abstract public function opendir($path);
52
+    /**
53
+     * Open a directory handle for a folder
54
+     *
55
+     * @param string $path
56
+     * @return resource | bool
57
+     */
58
+    abstract public function opendir($path);
59 59
 
60
-	/**
61
-	 * Create a new folder
62
-	 *
63
-	 * @param string $path
64
-	 * @return bool
65
-	 */
66
-	abstract public function mkdir($path);
60
+    /**
61
+     * Create a new folder
62
+     *
63
+     * @param string $path
64
+     * @return bool
65
+     */
66
+    abstract public function mkdir($path);
67 67
 
68
-	public function copy($source, $target) {
69
-		if ($this->is_dir($source)) {
70
-			if ($this->file_exists($target)) {
71
-				$this->unlink($target);
72
-			}
73
-			$this->mkdir($target);
74
-			return $this->copyRecursive($source, $target);
75
-		} else {
76
-			return parent::copy($source, $target);
77
-		}
78
-	}
68
+    public function copy($source, $target) {
69
+        if ($this->is_dir($source)) {
70
+            if ($this->file_exists($target)) {
71
+                $this->unlink($target);
72
+            }
73
+            $this->mkdir($target);
74
+            return $this->copyRecursive($source, $target);
75
+        } else {
76
+            return parent::copy($source, $target);
77
+        }
78
+    }
79 79
 
80
-	/**
81
-	 * For adapters that don't support copying folders natively
82
-	 *
83
-	 * @param $source
84
-	 * @param $target
85
-	 * @return bool
86
-	 */
87
-	protected function copyRecursive($source, $target) {
88
-		$dh = $this->opendir($source);
89
-		$result = true;
90
-		while ($file = readdir($dh)) {
91
-			if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
92
-				if ($this->is_dir($source . '/' . $file)) {
93
-					$this->mkdir($target . '/' . $file);
94
-					$result = $this->copyRecursive($source . '/' . $file, $target . '/' . $file);
95
-				} else {
96
-					$result = parent::copy($source . '/' . $file, $target . '/' . $file);
97
-				}
98
-				if (!$result) {
99
-					break;
100
-				}
101
-			}
102
-		}
103
-		return $result;
104
-	}
80
+    /**
81
+     * For adapters that don't support copying folders natively
82
+     *
83
+     * @param $source
84
+     * @param $target
85
+     * @return bool
86
+     */
87
+    protected function copyRecursive($source, $target) {
88
+        $dh = $this->opendir($source);
89
+        $result = true;
90
+        while ($file = readdir($dh)) {
91
+            if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
92
+                if ($this->is_dir($source . '/' . $file)) {
93
+                    $this->mkdir($target . '/' . $file);
94
+                    $result = $this->copyRecursive($source . '/' . $file, $target . '/' . $file);
95
+                } else {
96
+                    $result = parent::copy($source . '/' . $file, $target . '/' . $file);
97
+                }
98
+                if (!$result) {
99
+                    break;
100
+                }
101
+            }
102
+        }
103
+        return $result;
104
+    }
105 105
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -89,11 +89,11 @@
 block discarded – undo
89 89
 		$result = true;
90 90
 		while ($file = readdir($dh)) {
91 91
 			if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
92
-				if ($this->is_dir($source . '/' . $file)) {
93
-					$this->mkdir($target . '/' . $file);
94
-					$result = $this->copyRecursive($source . '/' . $file, $target . '/' . $file);
92
+				if ($this->is_dir($source.'/'.$file)) {
93
+					$this->mkdir($target.'/'.$file);
94
+					$result = $this->copyRecursive($source.'/'.$file, $target.'/'.$file);
95 95
 				} else {
96
-					$result = parent::copy($source . '/' . $file, $target . '/' . $file);
96
+					$result = parent::copy($source.'/'.$file, $target.'/'.$file);
97 97
 				}
98 98
 				if (!$result) {
99 99
 					break;
Please login to merge, or discard this patch.