Passed
Push — master ( 645109...008e6d )
by Christoph
12:14 queued 12s
created
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/Common.php 3 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -289,7 +289,9 @@
 block discarded – undo
289 289
 		$dh = $this->opendir($dir);
290 290
 		if (is_resource($dh)) {
291 291
 			while (($item = readdir($dh)) !== false) {
292
-				if (\OC\Files\Filesystem::isIgnoredDir($item)) continue;
292
+				if (\OC\Files\Filesystem::isIgnoredDir($item)) {
293
+				    continue;
294
+				}
293 295
 				if (strstr(strtolower($item), strtolower($query)) !== false) {
294 296
 					$files[] = $dir . '/' . $item;
295 297
 				}
Please login to merge, or discard this patch.
Indentation   +782 added lines, -782 removed lines patch added patch discarded remove patch
@@ -76,790 +76,790 @@
 block discarded – undo
76 76
  */
77 77
 abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
78 78
 
79
-	use LocalTempFileTrait;
80
-
81
-	protected $cache;
82
-	protected $scanner;
83
-	protected $watcher;
84
-	protected $propagator;
85
-	protected $storageCache;
86
-	protected $updater;
87
-
88
-	protected $mountOptions = [];
89
-	protected $owner = null;
90
-
91
-	private $shouldLogLocks = null;
92
-	private $logger;
93
-
94
-	public function __construct($parameters) {
95
-	}
96
-
97
-	/**
98
-	 * Remove a file or folder
99
-	 *
100
-	 * @param string $path
101
-	 * @return bool
102
-	 */
103
-	protected function remove($path) {
104
-		if ($this->is_dir($path)) {
105
-			return $this->rmdir($path);
106
-		} else if ($this->is_file($path)) {
107
-			return $this->unlink($path);
108
-		} else {
109
-			return false;
110
-		}
111
-	}
112
-
113
-	public function is_dir($path) {
114
-		return $this->filetype($path) === 'dir';
115
-	}
116
-
117
-	public function is_file($path) {
118
-		return $this->filetype($path) === 'file';
119
-	}
120
-
121
-	public function filesize($path) {
122
-		if ($this->is_dir($path)) {
123
-			return 0; //by definition
124
-		} else {
125
-			$stat = $this->stat($path);
126
-			if (isset($stat['size'])) {
127
-				return $stat['size'];
128
-			} else {
129
-				return 0;
130
-			}
131
-		}
132
-	}
133
-
134
-	public function isReadable($path) {
135
-		// at least check whether it exists
136
-		// subclasses might want to implement this more thoroughly
137
-		return $this->file_exists($path);
138
-	}
139
-
140
-	public function isUpdatable($path) {
141
-		// at least check whether it exists
142
-		// subclasses might want to implement this more thoroughly
143
-		// a non-existing file/folder isn't updatable
144
-		return $this->file_exists($path);
145
-	}
146
-
147
-	public function isCreatable($path) {
148
-		if ($this->is_dir($path) && $this->isUpdatable($path)) {
149
-			return true;
150
-		}
151
-		return false;
152
-	}
153
-
154
-	public function isDeletable($path) {
155
-		if ($path === '' || $path === '/') {
156
-			return false;
157
-		}
158
-		$parent = dirname($path);
159
-		return $this->isUpdatable($parent) && $this->isUpdatable($path);
160
-	}
161
-
162
-	public function isSharable($path) {
163
-		return $this->isReadable($path);
164
-	}
165
-
166
-	public function getPermissions($path) {
167
-		$permissions = 0;
168
-		if ($this->isCreatable($path)) {
169
-			$permissions |= \OCP\Constants::PERMISSION_CREATE;
170
-		}
171
-		if ($this->isReadable($path)) {
172
-			$permissions |= \OCP\Constants::PERMISSION_READ;
173
-		}
174
-		if ($this->isUpdatable($path)) {
175
-			$permissions |= \OCP\Constants::PERMISSION_UPDATE;
176
-		}
177
-		if ($this->isDeletable($path)) {
178
-			$permissions |= \OCP\Constants::PERMISSION_DELETE;
179
-		}
180
-		if ($this->isSharable($path)) {
181
-			$permissions |= \OCP\Constants::PERMISSION_SHARE;
182
-		}
183
-		return $permissions;
184
-	}
185
-
186
-	public function filemtime($path) {
187
-		$stat = $this->stat($path);
188
-		if (isset($stat['mtime']) && $stat['mtime'] > 0) {
189
-			return $stat['mtime'];
190
-		} else {
191
-			return 0;
192
-		}
193
-	}
194
-
195
-	public function file_get_contents($path) {
196
-		$handle = $this->fopen($path, "r");
197
-		if (!$handle) {
198
-			return false;
199
-		}
200
-		$data = stream_get_contents($handle);
201
-		fclose($handle);
202
-		return $data;
203
-	}
204
-
205
-	public function file_put_contents($path, $data) {
206
-		$handle = $this->fopen($path, "w");
207
-		$this->removeCachedFile($path);
208
-		$count = fwrite($handle, $data);
209
-		fclose($handle);
210
-		return $count;
211
-	}
212
-
213
-	public function rename($path1, $path2) {
214
-		$this->remove($path2);
215
-
216
-		$this->removeCachedFile($path1);
217
-		return $this->copy($path1, $path2) and $this->remove($path1);
218
-	}
219
-
220
-	public function copy($path1, $path2) {
221
-		if ($this->is_dir($path1)) {
222
-			$this->remove($path2);
223
-			$dir = $this->opendir($path1);
224
-			$this->mkdir($path2);
225
-			while ($file = readdir($dir)) {
226
-				if (!Filesystem::isIgnoredDir($file)) {
227
-					if (!$this->copy($path1 . '/' . $file, $path2 . '/' . $file)) {
228
-						return false;
229
-					}
230
-				}
231
-			}
232
-			closedir($dir);
233
-			return true;
234
-		} else {
235
-			$source = $this->fopen($path1, 'r');
236
-			$target = $this->fopen($path2, 'w');
237
-			list(, $result) = \OC_Helper::streamCopy($source, $target);
238
-			if (!$result) {
239
-				\OC::$server->getLogger()->warning("Failed to write data while copying $path1 to $path2");
240
-			}
241
-			$this->removeCachedFile($path2);
242
-			return $result;
243
-		}
244
-	}
245
-
246
-	public function getMimeType($path) {
247
-		if ($this->is_dir($path)) {
248
-			return 'httpd/unix-directory';
249
-		} elseif ($this->file_exists($path)) {
250
-			return \OC::$server->getMimeTypeDetector()->detectPath($path);
251
-		} else {
252
-			return false;
253
-		}
254
-	}
255
-
256
-	public function hash($type, $path, $raw = false) {
257
-		$fh = $this->fopen($path, 'rb');
258
-		$ctx = hash_init($type);
259
-		hash_update_stream($ctx, $fh);
260
-		fclose($fh);
261
-		return hash_final($ctx, $raw);
262
-	}
263
-
264
-	public function search($query) {
265
-		return $this->searchInDir($query);
266
-	}
267
-
268
-	public function getLocalFile($path) {
269
-		return $this->getCachedFile($path);
270
-	}
271
-
272
-	/**
273
-	 * @param string $path
274
-	 * @param string $target
275
-	 */
276
-	private function addLocalFolder($path, $target) {
277
-		$dh = $this->opendir($path);
278
-		if (is_resource($dh)) {
279
-			while (($file = readdir($dh)) !== false) {
280
-				if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
281
-					if ($this->is_dir($path . '/' . $file)) {
282
-						mkdir($target . '/' . $file);
283
-						$this->addLocalFolder($path . '/' . $file, $target . '/' . $file);
284
-					} else {
285
-						$tmp = $this->toTmpFile($path . '/' . $file);
286
-						rename($tmp, $target . '/' . $file);
287
-					}
288
-				}
289
-			}
290
-		}
291
-	}
292
-
293
-	/**
294
-	 * @param string $query
295
-	 * @param string $dir
296
-	 * @return array
297
-	 */
298
-	protected function searchInDir($query, $dir = '') {
299
-		$files = [];
300
-		$dh = $this->opendir($dir);
301
-		if (is_resource($dh)) {
302
-			while (($item = readdir($dh)) !== false) {
303
-				if (\OC\Files\Filesystem::isIgnoredDir($item)) continue;
304
-				if (strstr(strtolower($item), strtolower($query)) !== false) {
305
-					$files[] = $dir . '/' . $item;
306
-				}
307
-				if ($this->is_dir($dir . '/' . $item)) {
308
-					$files = array_merge($files, $this->searchInDir($query, $dir . '/' . $item));
309
-				}
310
-			}
311
-		}
312
-		closedir($dh);
313
-		return $files;
314
-	}
315
-
316
-	/**
317
-	 * check if a file or folder has been updated since $time
318
-	 *
319
-	 * The method is only used to check if the cache needs to be updated. Storage backends that don't support checking
320
-	 * the mtime should always return false here. As a result storage implementations that always return false expect
321
-	 * exclusive access to the backend and will not pick up files that have been added in a way that circumvents
322
-	 * ownClouds filesystem.
323
-	 *
324
-	 * @param string $path
325
-	 * @param int $time
326
-	 * @return bool
327
-	 */
328
-	public function hasUpdated($path, $time) {
329
-		return $this->filemtime($path) > $time;
330
-	}
331
-
332
-	public function getCache($path = '', $storage = null) {
333
-		if (!$storage) {
334
-			$storage = $this;
335
-		}
336
-		if (!isset($storage->cache)) {
337
-			$storage->cache = new Cache($storage);
338
-		}
339
-		return $storage->cache;
340
-	}
341
-
342
-	public function getScanner($path = '', $storage = null) {
343
-		if (!$storage) {
344
-			$storage = $this;
345
-		}
346
-		if (!isset($storage->scanner)) {
347
-			$storage->scanner = new Scanner($storage);
348
-		}
349
-		return $storage->scanner;
350
-	}
351
-
352
-	public function getWatcher($path = '', $storage = null) {
353
-		if (!$storage) {
354
-			$storage = $this;
355
-		}
356
-		if (!isset($this->watcher)) {
357
-			$this->watcher = new Watcher($storage);
358
-			$globalPolicy = \OC::$server->getConfig()->getSystemValue('filesystem_check_changes', Watcher::CHECK_NEVER);
359
-			$this->watcher->setPolicy((int)$this->getMountOption('filesystem_check_changes', $globalPolicy));
360
-		}
361
-		return $this->watcher;
362
-	}
363
-
364
-	/**
365
-	 * get a propagator instance for the cache
366
-	 *
367
-	 * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher
368
-	 * @return \OC\Files\Cache\Propagator
369
-	 */
370
-	public function getPropagator($storage = null) {
371
-		if (!$storage) {
372
-			$storage = $this;
373
-		}
374
-		if (!isset($storage->propagator)) {
375
-			$config = \OC::$server->getSystemConfig();
376
-			$storage->propagator = new Propagator($storage, \OC::$server->getDatabaseConnection(), ['appdata_' . $config->getValue('instanceid')]);
377
-		}
378
-		return $storage->propagator;
379
-	}
380
-
381
-	public function getUpdater($storage = null) {
382
-		if (!$storage) {
383
-			$storage = $this;
384
-		}
385
-		if (!isset($storage->updater)) {
386
-			$storage->updater = new Updater($storage);
387
-		}
388
-		return $storage->updater;
389
-	}
390
-
391
-	public function getStorageCache($storage = null) {
392
-		if (!$storage) {
393
-			$storage = $this;
394
-		}
395
-		if (!isset($this->storageCache)) {
396
-			$this->storageCache = new \OC\Files\Cache\Storage($storage);
397
-		}
398
-		return $this->storageCache;
399
-	}
400
-
401
-	/**
402
-	 * get the owner of a path
403
-	 *
404
-	 * @param string $path The path to get the owner
405
-	 * @return string|false uid or false
406
-	 */
407
-	public function getOwner($path) {
408
-		if ($this->owner === null) {
409
-			$this->owner = \OC_User::getUser();
410
-		}
411
-
412
-		return $this->owner;
413
-	}
414
-
415
-	/**
416
-	 * get the ETag for a file or folder
417
-	 *
418
-	 * @param string $path
419
-	 * @return string
420
-	 */
421
-	public function getETag($path) {
422
-		return uniqid();
423
-	}
424
-
425
-	/**
426
-	 * clean a path, i.e. remove all redundant '.' and '..'
427
-	 * making sure that it can't point to higher than '/'
428
-	 *
429
-	 * @param string $path The path to clean
430
-	 * @return string cleaned path
431
-	 */
432
-	public function cleanPath($path) {
433
-		if (strlen($path) == 0 or $path[0] != '/') {
434
-			$path = '/' . $path;
435
-		}
436
-
437
-		$output = [];
438
-		foreach (explode('/', $path) as $chunk) {
439
-			if ($chunk == '..') {
440
-				array_pop($output);
441
-			} else if ($chunk == '.') {
442
-			} else {
443
-				$output[] = $chunk;
444
-			}
445
-		}
446
-		return implode('/', $output);
447
-	}
448
-
449
-	/**
450
-	 * Test a storage for availability
451
-	 *
452
-	 * @return bool
453
-	 */
454
-	public function test() {
455
-		try {
456
-			if ($this->stat('')) {
457
-				return true;
458
-			}
459
-			\OC::$server->getLogger()->info("External storage not available: stat() failed");
460
-			return false;
461
-		} catch (\Exception $e) {
462
-			\OC::$server->getLogger()->info("External storage not available: " . $e->getMessage());
463
-			\OC::$server->getLogger()->logException($e, ['level' => ILogger::DEBUG]);
464
-			return false;
465
-		}
466
-	}
467
-
468
-	/**
469
-	 * get the free space in the storage
470
-	 *
471
-	 * @param string $path
472
-	 * @return int|false
473
-	 */
474
-	public function free_space($path) {
475
-		return \OCP\Files\FileInfo::SPACE_UNKNOWN;
476
-	}
477
-
478
-	/**
479
-	 * {@inheritdoc}
480
-	 */
481
-	public function isLocal() {
482
-		// the common implementation returns a temporary file by
483
-		// default, which is not local
484
-		return false;
485
-	}
486
-
487
-	/**
488
-	 * Check if the storage is an instance of $class or is a wrapper for a storage that is an instance of $class
489
-	 *
490
-	 * @param string $class
491
-	 * @return bool
492
-	 */
493
-	public function instanceOfStorage($class) {
494
-		if (ltrim($class, '\\') === 'OC\Files\Storage\Shared') {
495
-			// FIXME Temporary fix to keep existing checks working
496
-			$class = '\OCA\Files_Sharing\SharedStorage';
497
-		}
498
-		return is_a($this, $class);
499
-	}
500
-
501
-	/**
502
-	 * A custom storage implementation can return an url for direct download of a give file.
503
-	 *
504
-	 * For now the returned array can hold the parameter url - in future more attributes might follow.
505
-	 *
506
-	 * @param string $path
507
-	 * @return array|false
508
-	 */
509
-	public function getDirectDownload($path) {
510
-		return [];
511
-	}
512
-
513
-	/**
514
-	 * @inheritdoc
515
-	 * @throws InvalidPathException
516
-	 */
517
-	public function verifyPath($path, $fileName) {
518
-
519
-		// verify empty and dot files
520
-		$trimmed = trim($fileName);
521
-		if ($trimmed === '') {
522
-			throw new EmptyFileNameException();
523
-		}
524
-
525
-		if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) {
526
-			throw new InvalidDirectoryException();
527
-		}
528
-
529
-		if (!\OC::$server->getDatabaseConnection()->supports4ByteText()) {
530
-			// verify database - e.g. mysql only 3-byte chars
531
-			if (preg_match('%(?:
79
+    use LocalTempFileTrait;
80
+
81
+    protected $cache;
82
+    protected $scanner;
83
+    protected $watcher;
84
+    protected $propagator;
85
+    protected $storageCache;
86
+    protected $updater;
87
+
88
+    protected $mountOptions = [];
89
+    protected $owner = null;
90
+
91
+    private $shouldLogLocks = null;
92
+    private $logger;
93
+
94
+    public function __construct($parameters) {
95
+    }
96
+
97
+    /**
98
+     * Remove a file or folder
99
+     *
100
+     * @param string $path
101
+     * @return bool
102
+     */
103
+    protected function remove($path) {
104
+        if ($this->is_dir($path)) {
105
+            return $this->rmdir($path);
106
+        } else if ($this->is_file($path)) {
107
+            return $this->unlink($path);
108
+        } else {
109
+            return false;
110
+        }
111
+    }
112
+
113
+    public function is_dir($path) {
114
+        return $this->filetype($path) === 'dir';
115
+    }
116
+
117
+    public function is_file($path) {
118
+        return $this->filetype($path) === 'file';
119
+    }
120
+
121
+    public function filesize($path) {
122
+        if ($this->is_dir($path)) {
123
+            return 0; //by definition
124
+        } else {
125
+            $stat = $this->stat($path);
126
+            if (isset($stat['size'])) {
127
+                return $stat['size'];
128
+            } else {
129
+                return 0;
130
+            }
131
+        }
132
+    }
133
+
134
+    public function isReadable($path) {
135
+        // at least check whether it exists
136
+        // subclasses might want to implement this more thoroughly
137
+        return $this->file_exists($path);
138
+    }
139
+
140
+    public function isUpdatable($path) {
141
+        // at least check whether it exists
142
+        // subclasses might want to implement this more thoroughly
143
+        // a non-existing file/folder isn't updatable
144
+        return $this->file_exists($path);
145
+    }
146
+
147
+    public function isCreatable($path) {
148
+        if ($this->is_dir($path) && $this->isUpdatable($path)) {
149
+            return true;
150
+        }
151
+        return false;
152
+    }
153
+
154
+    public function isDeletable($path) {
155
+        if ($path === '' || $path === '/') {
156
+            return false;
157
+        }
158
+        $parent = dirname($path);
159
+        return $this->isUpdatable($parent) && $this->isUpdatable($path);
160
+    }
161
+
162
+    public function isSharable($path) {
163
+        return $this->isReadable($path);
164
+    }
165
+
166
+    public function getPermissions($path) {
167
+        $permissions = 0;
168
+        if ($this->isCreatable($path)) {
169
+            $permissions |= \OCP\Constants::PERMISSION_CREATE;
170
+        }
171
+        if ($this->isReadable($path)) {
172
+            $permissions |= \OCP\Constants::PERMISSION_READ;
173
+        }
174
+        if ($this->isUpdatable($path)) {
175
+            $permissions |= \OCP\Constants::PERMISSION_UPDATE;
176
+        }
177
+        if ($this->isDeletable($path)) {
178
+            $permissions |= \OCP\Constants::PERMISSION_DELETE;
179
+        }
180
+        if ($this->isSharable($path)) {
181
+            $permissions |= \OCP\Constants::PERMISSION_SHARE;
182
+        }
183
+        return $permissions;
184
+    }
185
+
186
+    public function filemtime($path) {
187
+        $stat = $this->stat($path);
188
+        if (isset($stat['mtime']) && $stat['mtime'] > 0) {
189
+            return $stat['mtime'];
190
+        } else {
191
+            return 0;
192
+        }
193
+    }
194
+
195
+    public function file_get_contents($path) {
196
+        $handle = $this->fopen($path, "r");
197
+        if (!$handle) {
198
+            return false;
199
+        }
200
+        $data = stream_get_contents($handle);
201
+        fclose($handle);
202
+        return $data;
203
+    }
204
+
205
+    public function file_put_contents($path, $data) {
206
+        $handle = $this->fopen($path, "w");
207
+        $this->removeCachedFile($path);
208
+        $count = fwrite($handle, $data);
209
+        fclose($handle);
210
+        return $count;
211
+    }
212
+
213
+    public function rename($path1, $path2) {
214
+        $this->remove($path2);
215
+
216
+        $this->removeCachedFile($path1);
217
+        return $this->copy($path1, $path2) and $this->remove($path1);
218
+    }
219
+
220
+    public function copy($path1, $path2) {
221
+        if ($this->is_dir($path1)) {
222
+            $this->remove($path2);
223
+            $dir = $this->opendir($path1);
224
+            $this->mkdir($path2);
225
+            while ($file = readdir($dir)) {
226
+                if (!Filesystem::isIgnoredDir($file)) {
227
+                    if (!$this->copy($path1 . '/' . $file, $path2 . '/' . $file)) {
228
+                        return false;
229
+                    }
230
+                }
231
+            }
232
+            closedir($dir);
233
+            return true;
234
+        } else {
235
+            $source = $this->fopen($path1, 'r');
236
+            $target = $this->fopen($path2, 'w');
237
+            list(, $result) = \OC_Helper::streamCopy($source, $target);
238
+            if (!$result) {
239
+                \OC::$server->getLogger()->warning("Failed to write data while copying $path1 to $path2");
240
+            }
241
+            $this->removeCachedFile($path2);
242
+            return $result;
243
+        }
244
+    }
245
+
246
+    public function getMimeType($path) {
247
+        if ($this->is_dir($path)) {
248
+            return 'httpd/unix-directory';
249
+        } elseif ($this->file_exists($path)) {
250
+            return \OC::$server->getMimeTypeDetector()->detectPath($path);
251
+        } else {
252
+            return false;
253
+        }
254
+    }
255
+
256
+    public function hash($type, $path, $raw = false) {
257
+        $fh = $this->fopen($path, 'rb');
258
+        $ctx = hash_init($type);
259
+        hash_update_stream($ctx, $fh);
260
+        fclose($fh);
261
+        return hash_final($ctx, $raw);
262
+    }
263
+
264
+    public function search($query) {
265
+        return $this->searchInDir($query);
266
+    }
267
+
268
+    public function getLocalFile($path) {
269
+        return $this->getCachedFile($path);
270
+    }
271
+
272
+    /**
273
+     * @param string $path
274
+     * @param string $target
275
+     */
276
+    private function addLocalFolder($path, $target) {
277
+        $dh = $this->opendir($path);
278
+        if (is_resource($dh)) {
279
+            while (($file = readdir($dh)) !== false) {
280
+                if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
281
+                    if ($this->is_dir($path . '/' . $file)) {
282
+                        mkdir($target . '/' . $file);
283
+                        $this->addLocalFolder($path . '/' . $file, $target . '/' . $file);
284
+                    } else {
285
+                        $tmp = $this->toTmpFile($path . '/' . $file);
286
+                        rename($tmp, $target . '/' . $file);
287
+                    }
288
+                }
289
+            }
290
+        }
291
+    }
292
+
293
+    /**
294
+     * @param string $query
295
+     * @param string $dir
296
+     * @return array
297
+     */
298
+    protected function searchInDir($query, $dir = '') {
299
+        $files = [];
300
+        $dh = $this->opendir($dir);
301
+        if (is_resource($dh)) {
302
+            while (($item = readdir($dh)) !== false) {
303
+                if (\OC\Files\Filesystem::isIgnoredDir($item)) continue;
304
+                if (strstr(strtolower($item), strtolower($query)) !== false) {
305
+                    $files[] = $dir . '/' . $item;
306
+                }
307
+                if ($this->is_dir($dir . '/' . $item)) {
308
+                    $files = array_merge($files, $this->searchInDir($query, $dir . '/' . $item));
309
+                }
310
+            }
311
+        }
312
+        closedir($dh);
313
+        return $files;
314
+    }
315
+
316
+    /**
317
+     * check if a file or folder has been updated since $time
318
+     *
319
+     * The method is only used to check if the cache needs to be updated. Storage backends that don't support checking
320
+     * the mtime should always return false here. As a result storage implementations that always return false expect
321
+     * exclusive access to the backend and will not pick up files that have been added in a way that circumvents
322
+     * ownClouds filesystem.
323
+     *
324
+     * @param string $path
325
+     * @param int $time
326
+     * @return bool
327
+     */
328
+    public function hasUpdated($path, $time) {
329
+        return $this->filemtime($path) > $time;
330
+    }
331
+
332
+    public function getCache($path = '', $storage = null) {
333
+        if (!$storage) {
334
+            $storage = $this;
335
+        }
336
+        if (!isset($storage->cache)) {
337
+            $storage->cache = new Cache($storage);
338
+        }
339
+        return $storage->cache;
340
+    }
341
+
342
+    public function getScanner($path = '', $storage = null) {
343
+        if (!$storage) {
344
+            $storage = $this;
345
+        }
346
+        if (!isset($storage->scanner)) {
347
+            $storage->scanner = new Scanner($storage);
348
+        }
349
+        return $storage->scanner;
350
+    }
351
+
352
+    public function getWatcher($path = '', $storage = null) {
353
+        if (!$storage) {
354
+            $storage = $this;
355
+        }
356
+        if (!isset($this->watcher)) {
357
+            $this->watcher = new Watcher($storage);
358
+            $globalPolicy = \OC::$server->getConfig()->getSystemValue('filesystem_check_changes', Watcher::CHECK_NEVER);
359
+            $this->watcher->setPolicy((int)$this->getMountOption('filesystem_check_changes', $globalPolicy));
360
+        }
361
+        return $this->watcher;
362
+    }
363
+
364
+    /**
365
+     * get a propagator instance for the cache
366
+     *
367
+     * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher
368
+     * @return \OC\Files\Cache\Propagator
369
+     */
370
+    public function getPropagator($storage = null) {
371
+        if (!$storage) {
372
+            $storage = $this;
373
+        }
374
+        if (!isset($storage->propagator)) {
375
+            $config = \OC::$server->getSystemConfig();
376
+            $storage->propagator = new Propagator($storage, \OC::$server->getDatabaseConnection(), ['appdata_' . $config->getValue('instanceid')]);
377
+        }
378
+        return $storage->propagator;
379
+    }
380
+
381
+    public function getUpdater($storage = null) {
382
+        if (!$storage) {
383
+            $storage = $this;
384
+        }
385
+        if (!isset($storage->updater)) {
386
+            $storage->updater = new Updater($storage);
387
+        }
388
+        return $storage->updater;
389
+    }
390
+
391
+    public function getStorageCache($storage = null) {
392
+        if (!$storage) {
393
+            $storage = $this;
394
+        }
395
+        if (!isset($this->storageCache)) {
396
+            $this->storageCache = new \OC\Files\Cache\Storage($storage);
397
+        }
398
+        return $this->storageCache;
399
+    }
400
+
401
+    /**
402
+     * get the owner of a path
403
+     *
404
+     * @param string $path The path to get the owner
405
+     * @return string|false uid or false
406
+     */
407
+    public function getOwner($path) {
408
+        if ($this->owner === null) {
409
+            $this->owner = \OC_User::getUser();
410
+        }
411
+
412
+        return $this->owner;
413
+    }
414
+
415
+    /**
416
+     * get the ETag for a file or folder
417
+     *
418
+     * @param string $path
419
+     * @return string
420
+     */
421
+    public function getETag($path) {
422
+        return uniqid();
423
+    }
424
+
425
+    /**
426
+     * clean a path, i.e. remove all redundant '.' and '..'
427
+     * making sure that it can't point to higher than '/'
428
+     *
429
+     * @param string $path The path to clean
430
+     * @return string cleaned path
431
+     */
432
+    public function cleanPath($path) {
433
+        if (strlen($path) == 0 or $path[0] != '/') {
434
+            $path = '/' . $path;
435
+        }
436
+
437
+        $output = [];
438
+        foreach (explode('/', $path) as $chunk) {
439
+            if ($chunk == '..') {
440
+                array_pop($output);
441
+            } else if ($chunk == '.') {
442
+            } else {
443
+                $output[] = $chunk;
444
+            }
445
+        }
446
+        return implode('/', $output);
447
+    }
448
+
449
+    /**
450
+     * Test a storage for availability
451
+     *
452
+     * @return bool
453
+     */
454
+    public function test() {
455
+        try {
456
+            if ($this->stat('')) {
457
+                return true;
458
+            }
459
+            \OC::$server->getLogger()->info("External storage not available: stat() failed");
460
+            return false;
461
+        } catch (\Exception $e) {
462
+            \OC::$server->getLogger()->info("External storage not available: " . $e->getMessage());
463
+            \OC::$server->getLogger()->logException($e, ['level' => ILogger::DEBUG]);
464
+            return false;
465
+        }
466
+    }
467
+
468
+    /**
469
+     * get the free space in the storage
470
+     *
471
+     * @param string $path
472
+     * @return int|false
473
+     */
474
+    public function free_space($path) {
475
+        return \OCP\Files\FileInfo::SPACE_UNKNOWN;
476
+    }
477
+
478
+    /**
479
+     * {@inheritdoc}
480
+     */
481
+    public function isLocal() {
482
+        // the common implementation returns a temporary file by
483
+        // default, which is not local
484
+        return false;
485
+    }
486
+
487
+    /**
488
+     * Check if the storage is an instance of $class or is a wrapper for a storage that is an instance of $class
489
+     *
490
+     * @param string $class
491
+     * @return bool
492
+     */
493
+    public function instanceOfStorage($class) {
494
+        if (ltrim($class, '\\') === 'OC\Files\Storage\Shared') {
495
+            // FIXME Temporary fix to keep existing checks working
496
+            $class = '\OCA\Files_Sharing\SharedStorage';
497
+        }
498
+        return is_a($this, $class);
499
+    }
500
+
501
+    /**
502
+     * A custom storage implementation can return an url for direct download of a give file.
503
+     *
504
+     * For now the returned array can hold the parameter url - in future more attributes might follow.
505
+     *
506
+     * @param string $path
507
+     * @return array|false
508
+     */
509
+    public function getDirectDownload($path) {
510
+        return [];
511
+    }
512
+
513
+    /**
514
+     * @inheritdoc
515
+     * @throws InvalidPathException
516
+     */
517
+    public function verifyPath($path, $fileName) {
518
+
519
+        // verify empty and dot files
520
+        $trimmed = trim($fileName);
521
+        if ($trimmed === '') {
522
+            throw new EmptyFileNameException();
523
+        }
524
+
525
+        if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) {
526
+            throw new InvalidDirectoryException();
527
+        }
528
+
529
+        if (!\OC::$server->getDatabaseConnection()->supports4ByteText()) {
530
+            // verify database - e.g. mysql only 3-byte chars
531
+            if (preg_match('%(?:
532 532
       \xF0[\x90-\xBF][\x80-\xBF]{2}      # planes 1-3
533 533
     | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
534 534
     | \xF4[\x80-\x8F][\x80-\xBF]{2}      # plane 16
535 535
 )%xs', $fileName)) {
536
-				throw new InvalidCharacterInPathException();
537
-			}
538
-		}
539
-
540
-		// 255 characters is the limit on common file systems (ext/xfs)
541
-		// oc_filecache has a 250 char length limit for the filename
542
-		if (isset($fileName[250])) {
543
-			throw new FileNameTooLongException();
544
-		}
545
-
546
-		// NOTE: $path will remain unverified for now
547
-		$this->verifyPosixPath($fileName);
548
-	}
549
-
550
-	/**
551
-	 * @param string $fileName
552
-	 * @throws InvalidPathException
553
-	 */
554
-	protected function verifyPosixPath($fileName) {
555
-		$fileName = trim($fileName);
556
-		$this->scanForInvalidCharacters($fileName, "\\/");
557
-		$reservedNames = ['*'];
558
-		if (in_array($fileName, $reservedNames)) {
559
-			throw new ReservedWordException();
560
-		}
561
-	}
562
-
563
-	/**
564
-	 * @param string $fileName
565
-	 * @param string $invalidChars
566
-	 * @throws InvalidPathException
567
-	 */
568
-	private function scanForInvalidCharacters($fileName, $invalidChars) {
569
-		foreach (str_split($invalidChars) as $char) {
570
-			if (strpos($fileName, $char) !== false) {
571
-				throw new InvalidCharacterInPathException();
572
-			}
573
-		}
574
-
575
-		$sanitizedFileName = filter_var($fileName, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW);
576
-		if ($sanitizedFileName !== $fileName) {
577
-			throw new InvalidCharacterInPathException();
578
-		}
579
-	}
580
-
581
-	/**
582
-	 * @param array $options
583
-	 */
584
-	public function setMountOptions(array $options) {
585
-		$this->mountOptions = $options;
586
-	}
587
-
588
-	/**
589
-	 * @param string $name
590
-	 * @param mixed $default
591
-	 * @return mixed
592
-	 */
593
-	public function getMountOption($name, $default = null) {
594
-		return isset($this->mountOptions[$name]) ? $this->mountOptions[$name] : $default;
595
-	}
596
-
597
-	/**
598
-	 * @param IStorage $sourceStorage
599
-	 * @param string $sourceInternalPath
600
-	 * @param string $targetInternalPath
601
-	 * @param bool $preserveMtime
602
-	 * @return bool
603
-	 */
604
-	public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) {
605
-		if ($sourceStorage === $this) {
606
-			return $this->copy($sourceInternalPath, $targetInternalPath);
607
-		}
608
-
609
-		if ($sourceStorage->is_dir($sourceInternalPath)) {
610
-			$dh = $sourceStorage->opendir($sourceInternalPath);
611
-			$result = $this->mkdir($targetInternalPath);
612
-			if (is_resource($dh)) {
613
-				while ($result and ($file = readdir($dh)) !== false) {
614
-					if (!Filesystem::isIgnoredDir($file)) {
615
-						$result &= $this->copyFromStorage($sourceStorage, $sourceInternalPath . '/' . $file, $targetInternalPath . '/' . $file);
616
-					}
617
-				}
618
-			}
619
-		} else {
620
-			$source = $sourceStorage->fopen($sourceInternalPath, 'r');
621
-			// TODO: call fopen in a way that we execute again all storage wrappers
622
-			// to avoid that we bypass storage wrappers which perform important actions
623
-			// for this operation. Same is true for all other operations which
624
-			// are not the same as the original one.Once this is fixed we also
625
-			// need to adjust the encryption wrapper.
626
-			$target = $this->fopen($targetInternalPath, 'w');
627
-			list(, $result) = \OC_Helper::streamCopy($source, $target);
628
-			if ($result and $preserveMtime) {
629
-				$this->touch($targetInternalPath, $sourceStorage->filemtime($sourceInternalPath));
630
-			}
631
-			fclose($source);
632
-			fclose($target);
633
-
634
-			if (!$result) {
635
-				// delete partially written target file
636
-				$this->unlink($targetInternalPath);
637
-				// delete cache entry that was created by fopen
638
-				$this->getCache()->remove($targetInternalPath);
639
-			}
640
-		}
641
-		return (bool)$result;
642
-	}
643
-
644
-	/**
645
-	 * Check if a storage is the same as the current one, including wrapped storages
646
-	 *
647
-	 * @param IStorage $storage
648
-	 * @return bool
649
-	 */
650
-	private function isSameStorage(IStorage $storage): bool {
651
-		while ($storage->instanceOfStorage(Wrapper::class)) {
652
-			/**
653
-			 * @var Wrapper $sourceStorage
654
-			 */
655
-			$storage = $storage->getWrapperStorage();
656
-		}
657
-
658
-		return $storage === $this;
659
-	}
660
-
661
-	/**
662
-	 * @param IStorage $sourceStorage
663
-	 * @param string $sourceInternalPath
664
-	 * @param string $targetInternalPath
665
-	 * @return bool
666
-	 */
667
-	public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
668
-		if ($this->isSameStorage($sourceStorage)) {
669
-			// resolve any jailed paths
670
-			while ($sourceStorage->instanceOfStorage(Jail::class)) {
671
-				/**
672
-				 * @var Jail $sourceStorage
673
-				 */
674
-				$sourceInternalPath = $sourceStorage->getUnjailedPath($sourceInternalPath);
675
-				$sourceStorage = $sourceStorage->getUnjailedStorage();
676
-			}
677
-
678
-			return $this->rename($sourceInternalPath, $targetInternalPath);
679
-		}
680
-
681
-		if (!$sourceStorage->isDeletable($sourceInternalPath)) {
682
-			return false;
683
-		}
684
-
685
-		$result = $this->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, true);
686
-		if ($result) {
687
-			if ($sourceStorage->is_dir($sourceInternalPath)) {
688
-				$result &= $sourceStorage->rmdir($sourceInternalPath);
689
-			} else {
690
-				$result &= $sourceStorage->unlink($sourceInternalPath);
691
-			}
692
-		}
693
-		return $result;
694
-	}
695
-
696
-	/**
697
-	 * @inheritdoc
698
-	 */
699
-	public function getMetaData($path) {
700
-		$permissions = $this->getPermissions($path);
701
-		if (!$permissions & \OCP\Constants::PERMISSION_READ) {
702
-			//can't read, nothing we can do
703
-			return null;
704
-		}
705
-
706
-		$data = [];
707
-		$data['mimetype'] = $this->getMimeType($path);
708
-		$data['mtime'] = $this->filemtime($path);
709
-		if ($data['mtime'] === false) {
710
-			$data['mtime'] = time();
711
-		}
712
-		if ($data['mimetype'] == 'httpd/unix-directory') {
713
-			$data['size'] = -1; //unknown
714
-		} else {
715
-			$data['size'] = $this->filesize($path);
716
-		}
717
-		$data['etag'] = $this->getETag($path);
718
-		$data['storage_mtime'] = $data['mtime'];
719
-		$data['permissions'] = $permissions;
720
-
721
-		return $data;
722
-	}
723
-
724
-	/**
725
-	 * @param string $path
726
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
727
-	 * @param \OCP\Lock\ILockingProvider $provider
728
-	 * @throws \OCP\Lock\LockedException
729
-	 */
730
-	public function acquireLock($path, $type, ILockingProvider $provider) {
731
-		$logger = $this->getLockLogger();
732
-		if ($logger) {
733
-			$typeString = ($type === ILockingProvider::LOCK_SHARED) ? 'shared' : 'exclusive';
734
-			$logger->info(
735
-				sprintf(
736
-					'acquire %s lock on "%s" on storage "%s"',
737
-					$typeString,
738
-					$path,
739
-					$this->getId()
740
-				),
741
-				[
742
-					'app' => 'locking',
743
-				]
744
-			);
745
-		}
746
-		try {
747
-			$provider->acquireLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
748
-		} catch (LockedException $e) {
749
-			if ($logger) {
750
-				$logger->logException($e, ['level' => ILogger::INFO]);
751
-			}
752
-			throw $e;
753
-		}
754
-	}
755
-
756
-	/**
757
-	 * @param string $path
758
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
759
-	 * @param \OCP\Lock\ILockingProvider $provider
760
-	 * @throws \OCP\Lock\LockedException
761
-	 */
762
-	public function releaseLock($path, $type, ILockingProvider $provider) {
763
-		$logger = $this->getLockLogger();
764
-		if ($logger) {
765
-			$typeString = ($type === ILockingProvider::LOCK_SHARED) ? 'shared' : 'exclusive';
766
-			$logger->info(
767
-				sprintf(
768
-					'release %s lock on "%s" on storage "%s"',
769
-					$typeString,
770
-					$path,
771
-					$this->getId()
772
-				),
773
-				[
774
-					'app' => 'locking',
775
-				]
776
-			);
777
-		}
778
-		try {
779
-			$provider->releaseLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
780
-		} catch (LockedException $e) {
781
-			if ($logger) {
782
-				$logger->logException($e, ['level' => ILogger::INFO]);
783
-			}
784
-			throw $e;
785
-		}
786
-	}
787
-
788
-	/**
789
-	 * @param string $path
790
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
791
-	 * @param \OCP\Lock\ILockingProvider $provider
792
-	 * @throws \OCP\Lock\LockedException
793
-	 */
794
-	public function changeLock($path, $type, ILockingProvider $provider) {
795
-		$logger = $this->getLockLogger();
796
-		if ($logger) {
797
-			$typeString = ($type === ILockingProvider::LOCK_SHARED) ? 'shared' : 'exclusive';
798
-			$logger->info(
799
-				sprintf(
800
-					'change lock on "%s" to %s on storage "%s"',
801
-					$path,
802
-					$typeString,
803
-					$this->getId()
804
-				),
805
-				[
806
-					'app' => 'locking',
807
-				]
808
-			);
809
-		}
810
-		try {
811
-			$provider->changeLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
812
-		} catch (LockedException $e) {
813
-			\OC::$server->getLogger()->logException($e, ['level' => ILogger::INFO]);
814
-			throw $e;
815
-		}
816
-	}
817
-
818
-	private function getLockLogger() {
819
-		if (is_null($this->shouldLogLocks)) {
820
-			$this->shouldLogLocks = \OC::$server->getConfig()->getSystemValue('filelocking.debug', false);
821
-			$this->logger = $this->shouldLogLocks ? \OC::$server->getLogger() : null;
822
-		}
823
-		return $this->logger;
824
-	}
825
-
826
-	/**
827
-	 * @return array [ available, last_checked ]
828
-	 */
829
-	public function getAvailability() {
830
-		return $this->getStorageCache()->getAvailability();
831
-	}
832
-
833
-	/**
834
-	 * @param bool $isAvailable
835
-	 */
836
-	public function setAvailability($isAvailable) {
837
-		$this->getStorageCache()->setAvailability($isAvailable);
838
-	}
839
-
840
-	/**
841
-	 * @return bool
842
-	 */
843
-	public function needsPartFile() {
844
-		return true;
845
-	}
846
-
847
-	/**
848
-	 * fallback implementation
849
-	 *
850
-	 * @param string $path
851
-	 * @param resource $stream
852
-	 * @param int $size
853
-	 * @return int
854
-	 */
855
-	public function writeStream(string $path, $stream, int $size = null): int {
856
-		$target = $this->fopen($path, 'w');
857
-		if (!$target) {
858
-			return 0;
859
-		}
860
-		list($count, $result) = \OC_Helper::streamCopy($stream, $target);
861
-		fclose($stream);
862
-		fclose($target);
863
-		return $count;
864
-	}
536
+                throw new InvalidCharacterInPathException();
537
+            }
538
+        }
539
+
540
+        // 255 characters is the limit on common file systems (ext/xfs)
541
+        // oc_filecache has a 250 char length limit for the filename
542
+        if (isset($fileName[250])) {
543
+            throw new FileNameTooLongException();
544
+        }
545
+
546
+        // NOTE: $path will remain unverified for now
547
+        $this->verifyPosixPath($fileName);
548
+    }
549
+
550
+    /**
551
+     * @param string $fileName
552
+     * @throws InvalidPathException
553
+     */
554
+    protected function verifyPosixPath($fileName) {
555
+        $fileName = trim($fileName);
556
+        $this->scanForInvalidCharacters($fileName, "\\/");
557
+        $reservedNames = ['*'];
558
+        if (in_array($fileName, $reservedNames)) {
559
+            throw new ReservedWordException();
560
+        }
561
+    }
562
+
563
+    /**
564
+     * @param string $fileName
565
+     * @param string $invalidChars
566
+     * @throws InvalidPathException
567
+     */
568
+    private function scanForInvalidCharacters($fileName, $invalidChars) {
569
+        foreach (str_split($invalidChars) as $char) {
570
+            if (strpos($fileName, $char) !== false) {
571
+                throw new InvalidCharacterInPathException();
572
+            }
573
+        }
574
+
575
+        $sanitizedFileName = filter_var($fileName, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW);
576
+        if ($sanitizedFileName !== $fileName) {
577
+            throw new InvalidCharacterInPathException();
578
+        }
579
+    }
580
+
581
+    /**
582
+     * @param array $options
583
+     */
584
+    public function setMountOptions(array $options) {
585
+        $this->mountOptions = $options;
586
+    }
587
+
588
+    /**
589
+     * @param string $name
590
+     * @param mixed $default
591
+     * @return mixed
592
+     */
593
+    public function getMountOption($name, $default = null) {
594
+        return isset($this->mountOptions[$name]) ? $this->mountOptions[$name] : $default;
595
+    }
596
+
597
+    /**
598
+     * @param IStorage $sourceStorage
599
+     * @param string $sourceInternalPath
600
+     * @param string $targetInternalPath
601
+     * @param bool $preserveMtime
602
+     * @return bool
603
+     */
604
+    public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) {
605
+        if ($sourceStorage === $this) {
606
+            return $this->copy($sourceInternalPath, $targetInternalPath);
607
+        }
608
+
609
+        if ($sourceStorage->is_dir($sourceInternalPath)) {
610
+            $dh = $sourceStorage->opendir($sourceInternalPath);
611
+            $result = $this->mkdir($targetInternalPath);
612
+            if (is_resource($dh)) {
613
+                while ($result and ($file = readdir($dh)) !== false) {
614
+                    if (!Filesystem::isIgnoredDir($file)) {
615
+                        $result &= $this->copyFromStorage($sourceStorage, $sourceInternalPath . '/' . $file, $targetInternalPath . '/' . $file);
616
+                    }
617
+                }
618
+            }
619
+        } else {
620
+            $source = $sourceStorage->fopen($sourceInternalPath, 'r');
621
+            // TODO: call fopen in a way that we execute again all storage wrappers
622
+            // to avoid that we bypass storage wrappers which perform important actions
623
+            // for this operation. Same is true for all other operations which
624
+            // are not the same as the original one.Once this is fixed we also
625
+            // need to adjust the encryption wrapper.
626
+            $target = $this->fopen($targetInternalPath, 'w');
627
+            list(, $result) = \OC_Helper::streamCopy($source, $target);
628
+            if ($result and $preserveMtime) {
629
+                $this->touch($targetInternalPath, $sourceStorage->filemtime($sourceInternalPath));
630
+            }
631
+            fclose($source);
632
+            fclose($target);
633
+
634
+            if (!$result) {
635
+                // delete partially written target file
636
+                $this->unlink($targetInternalPath);
637
+                // delete cache entry that was created by fopen
638
+                $this->getCache()->remove($targetInternalPath);
639
+            }
640
+        }
641
+        return (bool)$result;
642
+    }
643
+
644
+    /**
645
+     * Check if a storage is the same as the current one, including wrapped storages
646
+     *
647
+     * @param IStorage $storage
648
+     * @return bool
649
+     */
650
+    private function isSameStorage(IStorage $storage): bool {
651
+        while ($storage->instanceOfStorage(Wrapper::class)) {
652
+            /**
653
+             * @var Wrapper $sourceStorage
654
+             */
655
+            $storage = $storage->getWrapperStorage();
656
+        }
657
+
658
+        return $storage === $this;
659
+    }
660
+
661
+    /**
662
+     * @param IStorage $sourceStorage
663
+     * @param string $sourceInternalPath
664
+     * @param string $targetInternalPath
665
+     * @return bool
666
+     */
667
+    public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
668
+        if ($this->isSameStorage($sourceStorage)) {
669
+            // resolve any jailed paths
670
+            while ($sourceStorage->instanceOfStorage(Jail::class)) {
671
+                /**
672
+                 * @var Jail $sourceStorage
673
+                 */
674
+                $sourceInternalPath = $sourceStorage->getUnjailedPath($sourceInternalPath);
675
+                $sourceStorage = $sourceStorage->getUnjailedStorage();
676
+            }
677
+
678
+            return $this->rename($sourceInternalPath, $targetInternalPath);
679
+        }
680
+
681
+        if (!$sourceStorage->isDeletable($sourceInternalPath)) {
682
+            return false;
683
+        }
684
+
685
+        $result = $this->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, true);
686
+        if ($result) {
687
+            if ($sourceStorage->is_dir($sourceInternalPath)) {
688
+                $result &= $sourceStorage->rmdir($sourceInternalPath);
689
+            } else {
690
+                $result &= $sourceStorage->unlink($sourceInternalPath);
691
+            }
692
+        }
693
+        return $result;
694
+    }
695
+
696
+    /**
697
+     * @inheritdoc
698
+     */
699
+    public function getMetaData($path) {
700
+        $permissions = $this->getPermissions($path);
701
+        if (!$permissions & \OCP\Constants::PERMISSION_READ) {
702
+            //can't read, nothing we can do
703
+            return null;
704
+        }
705
+
706
+        $data = [];
707
+        $data['mimetype'] = $this->getMimeType($path);
708
+        $data['mtime'] = $this->filemtime($path);
709
+        if ($data['mtime'] === false) {
710
+            $data['mtime'] = time();
711
+        }
712
+        if ($data['mimetype'] == 'httpd/unix-directory') {
713
+            $data['size'] = -1; //unknown
714
+        } else {
715
+            $data['size'] = $this->filesize($path);
716
+        }
717
+        $data['etag'] = $this->getETag($path);
718
+        $data['storage_mtime'] = $data['mtime'];
719
+        $data['permissions'] = $permissions;
720
+
721
+        return $data;
722
+    }
723
+
724
+    /**
725
+     * @param string $path
726
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
727
+     * @param \OCP\Lock\ILockingProvider $provider
728
+     * @throws \OCP\Lock\LockedException
729
+     */
730
+    public function acquireLock($path, $type, ILockingProvider $provider) {
731
+        $logger = $this->getLockLogger();
732
+        if ($logger) {
733
+            $typeString = ($type === ILockingProvider::LOCK_SHARED) ? 'shared' : 'exclusive';
734
+            $logger->info(
735
+                sprintf(
736
+                    'acquire %s lock on "%s" on storage "%s"',
737
+                    $typeString,
738
+                    $path,
739
+                    $this->getId()
740
+                ),
741
+                [
742
+                    'app' => 'locking',
743
+                ]
744
+            );
745
+        }
746
+        try {
747
+            $provider->acquireLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
748
+        } catch (LockedException $e) {
749
+            if ($logger) {
750
+                $logger->logException($e, ['level' => ILogger::INFO]);
751
+            }
752
+            throw $e;
753
+        }
754
+    }
755
+
756
+    /**
757
+     * @param string $path
758
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
759
+     * @param \OCP\Lock\ILockingProvider $provider
760
+     * @throws \OCP\Lock\LockedException
761
+     */
762
+    public function releaseLock($path, $type, ILockingProvider $provider) {
763
+        $logger = $this->getLockLogger();
764
+        if ($logger) {
765
+            $typeString = ($type === ILockingProvider::LOCK_SHARED) ? 'shared' : 'exclusive';
766
+            $logger->info(
767
+                sprintf(
768
+                    'release %s lock on "%s" on storage "%s"',
769
+                    $typeString,
770
+                    $path,
771
+                    $this->getId()
772
+                ),
773
+                [
774
+                    'app' => 'locking',
775
+                ]
776
+            );
777
+        }
778
+        try {
779
+            $provider->releaseLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
780
+        } catch (LockedException $e) {
781
+            if ($logger) {
782
+                $logger->logException($e, ['level' => ILogger::INFO]);
783
+            }
784
+            throw $e;
785
+        }
786
+    }
787
+
788
+    /**
789
+     * @param string $path
790
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
791
+     * @param \OCP\Lock\ILockingProvider $provider
792
+     * @throws \OCP\Lock\LockedException
793
+     */
794
+    public function changeLock($path, $type, ILockingProvider $provider) {
795
+        $logger = $this->getLockLogger();
796
+        if ($logger) {
797
+            $typeString = ($type === ILockingProvider::LOCK_SHARED) ? 'shared' : 'exclusive';
798
+            $logger->info(
799
+                sprintf(
800
+                    'change lock on "%s" to %s on storage "%s"',
801
+                    $path,
802
+                    $typeString,
803
+                    $this->getId()
804
+                ),
805
+                [
806
+                    'app' => 'locking',
807
+                ]
808
+            );
809
+        }
810
+        try {
811
+            $provider->changeLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
812
+        } catch (LockedException $e) {
813
+            \OC::$server->getLogger()->logException($e, ['level' => ILogger::INFO]);
814
+            throw $e;
815
+        }
816
+    }
817
+
818
+    private function getLockLogger() {
819
+        if (is_null($this->shouldLogLocks)) {
820
+            $this->shouldLogLocks = \OC::$server->getConfig()->getSystemValue('filelocking.debug', false);
821
+            $this->logger = $this->shouldLogLocks ? \OC::$server->getLogger() : null;
822
+        }
823
+        return $this->logger;
824
+    }
825
+
826
+    /**
827
+     * @return array [ available, last_checked ]
828
+     */
829
+    public function getAvailability() {
830
+        return $this->getStorageCache()->getAvailability();
831
+    }
832
+
833
+    /**
834
+     * @param bool $isAvailable
835
+     */
836
+    public function setAvailability($isAvailable) {
837
+        $this->getStorageCache()->setAvailability($isAvailable);
838
+    }
839
+
840
+    /**
841
+     * @return bool
842
+     */
843
+    public function needsPartFile() {
844
+        return true;
845
+    }
846
+
847
+    /**
848
+     * fallback implementation
849
+     *
850
+     * @param string $path
851
+     * @param resource $stream
852
+     * @param int $size
853
+     * @return int
854
+     */
855
+    public function writeStream(string $path, $stream, int $size = null): int {
856
+        $target = $this->fopen($path, 'w');
857
+        if (!$target) {
858
+            return 0;
859
+        }
860
+        list($count, $result) = \OC_Helper::streamCopy($stream, $target);
861
+        fclose($stream);
862
+        fclose($target);
863
+        return $count;
864
+    }
865 865
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 			$this->mkdir($path2);
225 225
 			while ($file = readdir($dir)) {
226 226
 				if (!Filesystem::isIgnoredDir($file)) {
227
-					if (!$this->copy($path1 . '/' . $file, $path2 . '/' . $file)) {
227
+					if (!$this->copy($path1.'/'.$file, $path2.'/'.$file)) {
228 228
 						return false;
229 229
 					}
230 230
 				}
@@ -278,12 +278,12 @@  discard block
 block discarded – undo
278 278
 		if (is_resource($dh)) {
279 279
 			while (($file = readdir($dh)) !== false) {
280 280
 				if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
281
-					if ($this->is_dir($path . '/' . $file)) {
282
-						mkdir($target . '/' . $file);
283
-						$this->addLocalFolder($path . '/' . $file, $target . '/' . $file);
281
+					if ($this->is_dir($path.'/'.$file)) {
282
+						mkdir($target.'/'.$file);
283
+						$this->addLocalFolder($path.'/'.$file, $target.'/'.$file);
284 284
 					} else {
285
-						$tmp = $this->toTmpFile($path . '/' . $file);
286
-						rename($tmp, $target . '/' . $file);
285
+						$tmp = $this->toTmpFile($path.'/'.$file);
286
+						rename($tmp, $target.'/'.$file);
287 287
 					}
288 288
 				}
289 289
 			}
@@ -302,10 +302,10 @@  discard block
 block discarded – undo
302 302
 			while (($item = readdir($dh)) !== false) {
303 303
 				if (\OC\Files\Filesystem::isIgnoredDir($item)) continue;
304 304
 				if (strstr(strtolower($item), strtolower($query)) !== false) {
305
-					$files[] = $dir . '/' . $item;
305
+					$files[] = $dir.'/'.$item;
306 306
 				}
307
-				if ($this->is_dir($dir . '/' . $item)) {
308
-					$files = array_merge($files, $this->searchInDir($query, $dir . '/' . $item));
307
+				if ($this->is_dir($dir.'/'.$item)) {
308
+					$files = array_merge($files, $this->searchInDir($query, $dir.'/'.$item));
309 309
 				}
310 310
 			}
311 311
 		}
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 		if (!isset($this->watcher)) {
357 357
 			$this->watcher = new Watcher($storage);
358 358
 			$globalPolicy = \OC::$server->getConfig()->getSystemValue('filesystem_check_changes', Watcher::CHECK_NEVER);
359
-			$this->watcher->setPolicy((int)$this->getMountOption('filesystem_check_changes', $globalPolicy));
359
+			$this->watcher->setPolicy((int) $this->getMountOption('filesystem_check_changes', $globalPolicy));
360 360
 		}
361 361
 		return $this->watcher;
362 362
 	}
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
 		}
374 374
 		if (!isset($storage->propagator)) {
375 375
 			$config = \OC::$server->getSystemConfig();
376
-			$storage->propagator = new Propagator($storage, \OC::$server->getDatabaseConnection(), ['appdata_' . $config->getValue('instanceid')]);
376
+			$storage->propagator = new Propagator($storage, \OC::$server->getDatabaseConnection(), ['appdata_'.$config->getValue('instanceid')]);
377 377
 		}
378 378
 		return $storage->propagator;
379 379
 	}
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 	 */
432 432
 	public function cleanPath($path) {
433 433
 		if (strlen($path) == 0 or $path[0] != '/') {
434
-			$path = '/' . $path;
434
+			$path = '/'.$path;
435 435
 		}
436 436
 
437 437
 		$output = [];
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
 			\OC::$server->getLogger()->info("External storage not available: stat() failed");
460 460
 			return false;
461 461
 		} catch (\Exception $e) {
462
-			\OC::$server->getLogger()->info("External storage not available: " . $e->getMessage());
462
+			\OC::$server->getLogger()->info("External storage not available: ".$e->getMessage());
463 463
 			\OC::$server->getLogger()->logException($e, ['level' => ILogger::DEBUG]);
464 464
 			return false;
465 465
 		}
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
 			if (is_resource($dh)) {
613 613
 				while ($result and ($file = readdir($dh)) !== false) {
614 614
 					if (!Filesystem::isIgnoredDir($file)) {
615
-						$result &= $this->copyFromStorage($sourceStorage, $sourceInternalPath . '/' . $file, $targetInternalPath . '/' . $file);
615
+						$result &= $this->copyFromStorage($sourceStorage, $sourceInternalPath.'/'.$file, $targetInternalPath.'/'.$file);
616 616
 					}
617 617
 				}
618 618
 			}
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
 				$this->getCache()->remove($targetInternalPath);
639 639
 			}
640 640
 		}
641
-		return (bool)$result;
641
+		return (bool) $result;
642 642
 	}
643 643
 
644 644
 	/**
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
 			);
745 745
 		}
746 746
 		try {
747
-			$provider->acquireLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
747
+			$provider->acquireLock('files/'.md5($this->getId().'::'.trim($path, '/')), $type);
748 748
 		} catch (LockedException $e) {
749 749
 			if ($logger) {
750 750
 				$logger->logException($e, ['level' => ILogger::INFO]);
@@ -776,7 +776,7 @@  discard block
 block discarded – undo
776 776
 			);
777 777
 		}
778 778
 		try {
779
-			$provider->releaseLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
779
+			$provider->releaseLock('files/'.md5($this->getId().'::'.trim($path, '/')), $type);
780 780
 		} catch (LockedException $e) {
781 781
 			if ($logger) {
782 782
 				$logger->logException($e, ['level' => ILogger::INFO]);
@@ -808,7 +808,7 @@  discard block
 block discarded – undo
808 808
 			);
809 809
 		}
810 810
 		try {
811
-			$provider->changeLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
811
+			$provider->changeLock('files/'.md5($this->getId().'::'.trim($path, '/')), $type);
812 812
 		} catch (LockedException $e) {
813 813
 			\OC::$server->getLogger()->logException($e, ['level' => ILogger::INFO]);
814 814
 			throw $e;
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.
lib/private/Files/Notify/RenameChange.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -26,27 +26,27 @@
 block discarded – undo
26 26
 use OCP\Files\Notify\IRenameChange;
27 27
 
28 28
 class RenameChange extends Change implements IRenameChange {
29
-	/** @var string */
30
-	private $targetPath;
29
+    /** @var string */
30
+    private $targetPath;
31 31
 
32
-	/**
33
-	 * Change constructor.
34
-	 *
35
-	 * @param int $type
36
-	 * @param string $path
37
-	 * @param string $targetPath
38
-	 */
39
-	public function __construct($type, $path, $targetPath) {
40
-		parent::__construct($type, $path);
41
-		$this->targetPath = $targetPath;
42
-	}
32
+    /**
33
+     * Change constructor.
34
+     *
35
+     * @param int $type
36
+     * @param string $path
37
+     * @param string $targetPath
38
+     */
39
+    public function __construct($type, $path, $targetPath) {
40
+        parent::__construct($type, $path);
41
+        $this->targetPath = $targetPath;
42
+    }
43 43
 
44
-	/**
45
-	 * Get the new path of the renamed file relative to the storage root
46
-	 *
47
-	 * @return string
48
-	 */
49
-	public function getTargetPath() {
50
-		return $this->targetPath;
51
-	}
44
+    /**
45
+     * Get the new path of the renamed file relative to the storage root
46
+     *
47
+     * @return string
48
+     */
49
+    public function getTargetPath() {
50
+        return $this->targetPath;
51
+    }
52 52
 }
Please login to merge, or discard this patch.
lib/private/Files/Notify/Change.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -26,40 +26,40 @@
 block discarded – undo
26 26
 use OCP\Files\Notify\IChange;
27 27
 
28 28
 class Change implements IChange {
29
-	/** @var int */
30
-	private $type;
29
+    /** @var int */
30
+    private $type;
31 31
 
32
-	/** @var string */
33
-	private $path;
32
+    /** @var string */
33
+    private $path;
34 34
 
35
-	/**
36
-	 * Change constructor.
37
-	 *
38
-	 * @param int $type
39
-	 * @param string $path
40
-	 */
41
-	public function __construct($type, $path) {
42
-		$this->type = $type;
43
-		$this->path = $path;
44
-	}
35
+    /**
36
+     * Change constructor.
37
+     *
38
+     * @param int $type
39
+     * @param string $path
40
+     */
41
+    public function __construct($type, $path) {
42
+        $this->type = $type;
43
+        $this->path = $path;
44
+    }
45 45
 
46
-	/**
47
-	 * Get the type of the change
48
-	 *
49
-	 * @return int IChange::ADDED, IChange::REMOVED, IChange::MODIFIED or IChange::RENAMED
50
-	 */
51
-	public function getType() {
52
-		return $this->type;
53
-	}
46
+    /**
47
+     * Get the type of the change
48
+     *
49
+     * @return int IChange::ADDED, IChange::REMOVED, IChange::MODIFIED or IChange::RENAMED
50
+     */
51
+    public function getType() {
52
+        return $this->type;
53
+    }
54 54
 
55
-	/**
56
-	 * Get the path of the file that was changed relative to the root of the storage
57
-	 *
58
-	 * Note, for rename changes this path is the old path for the file
59
-	 *
60
-	 * @return mixed
61
-	 */
62
-	public function getPath() {
63
-		return $this->path;
64
-	}
55
+    /**
56
+     * Get the path of the file that was changed relative to the root of the storage
57
+     *
58
+     * Note, for rename changes this path is the old path for the file
59
+     *
60
+     * @return mixed
61
+     */
62
+    public function getPath() {
63
+        return $this->path;
64
+    }
65 65
 }
Please login to merge, or discard this patch.
lib/private/Files/Cache/HomePropagator.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -25,28 +25,28 @@
 block discarded – undo
25 25
 use OCP\IDBConnection;
26 26
 
27 27
 class HomePropagator extends Propagator {
28
-	private $ignoredBaseFolders;
28
+    private $ignoredBaseFolders;
29 29
 
30
-	/**
31
-	 * @param \OC\Files\Storage\Storage $storage
32
-	 */
33
-	public function __construct(\OC\Files\Storage\Storage $storage, IDBConnection $connection) {
34
-		parent::__construct($storage, $connection);
35
-		$this->ignoredBaseFolders = ['files_encryption'];
36
-	}
30
+    /**
31
+     * @param \OC\Files\Storage\Storage $storage
32
+     */
33
+    public function __construct(\OC\Files\Storage\Storage $storage, IDBConnection $connection) {
34
+        parent::__construct($storage, $connection);
35
+        $this->ignoredBaseFolders = ['files_encryption'];
36
+    }
37 37
 
38 38
 
39
-	/**
40
-	 * @param string $internalPath
41
-	 * @param int $time
42
-	 * @param int $sizeDifference number of bytes the file has grown
43
-	 */
44
-	public function propagateChange($internalPath, $time, $sizeDifference = 0) {
45
-		list($baseFolder) = explode('/', $internalPath, 2);
46
-		if (in_array($baseFolder, $this->ignoredBaseFolders)) {
47
-			return [];
48
-		} else {
49
-			parent::propagateChange($internalPath, $time, $sizeDifference);
50
-		}
51
-	}
39
+    /**
40
+     * @param string $internalPath
41
+     * @param int $time
42
+     * @param int $sizeDifference number of bytes the file has grown
43
+     */
44
+    public function propagateChange($internalPath, $time, $sizeDifference = 0) {
45
+        list($baseFolder) = explode('/', $internalPath, 2);
46
+        if (in_array($baseFolder, $this->ignoredBaseFolders)) {
47
+            return [];
48
+        } else {
49
+            parent::propagateChange($internalPath, $time, $sizeDifference);
50
+        }
51
+    }
52 52
 }
Please login to merge, or discard this patch.
lib/private/Files/Cache/CacheEntry.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@
 block discarded – undo
58 58
 	}
59 59
 
60 60
 	public function getId() {
61
-		return (int)$this->data['fileid'];
61
+		return (int) $this->data['fileid'];
62 62
 	}
63 63
 
64 64
 	public function getStorageId() {
Please login to merge, or discard this patch.
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -28,100 +28,100 @@
 block discarded – undo
28 28
  * meta data for a file or folder
29 29
  */
30 30
 class CacheEntry implements ICacheEntry, \ArrayAccess {
31
-	/**
32
-	 * @var array
33
-	 */
34
-	private $data;
31
+    /**
32
+     * @var array
33
+     */
34
+    private $data;
35 35
 
36
-	public function __construct(array $data) {
37
-		$this->data = $data;
38
-	}
36
+    public function __construct(array $data) {
37
+        $this->data = $data;
38
+    }
39 39
 
40
-	public function offsetSet($offset, $value) {
41
-		$this->data[$offset] = $value;
42
-	}
40
+    public function offsetSet($offset, $value) {
41
+        $this->data[$offset] = $value;
42
+    }
43 43
 
44
-	public function offsetExists($offset) {
45
-		return isset($this->data[$offset]);
46
-	}
44
+    public function offsetExists($offset) {
45
+        return isset($this->data[$offset]);
46
+    }
47 47
 
48
-	public function offsetUnset($offset) {
49
-		unset($this->data[$offset]);
50
-	}
48
+    public function offsetUnset($offset) {
49
+        unset($this->data[$offset]);
50
+    }
51 51
 
52
-	public function offsetGet($offset) {
53
-		if (isset($this->data[$offset])) {
54
-			return $this->data[$offset];
55
-		} else {
56
-			return null;
57
-		}
58
-	}
52
+    public function offsetGet($offset) {
53
+        if (isset($this->data[$offset])) {
54
+            return $this->data[$offset];
55
+        } else {
56
+            return null;
57
+        }
58
+    }
59 59
 
60
-	public function getId() {
61
-		return (int)$this->data['fileid'];
62
-	}
60
+    public function getId() {
61
+        return (int)$this->data['fileid'];
62
+    }
63 63
 
64
-	public function getStorageId() {
65
-		return $this->data['storage'];
66
-	}
64
+    public function getStorageId() {
65
+        return $this->data['storage'];
66
+    }
67 67
 
68 68
 
69
-	public function getPath() {
70
-		return $this->data['path'];
71
-	}
69
+    public function getPath() {
70
+        return $this->data['path'];
71
+    }
72 72
 
73 73
 
74
-	public function getName() {
75
-		return $this->data['name'];
76
-	}
74
+    public function getName() {
75
+        return $this->data['name'];
76
+    }
77 77
 
78 78
 
79
-	public function getMimeType() {
80
-		return $this->data['mimetype'];
81
-	}
79
+    public function getMimeType() {
80
+        return $this->data['mimetype'];
81
+    }
82 82
 
83 83
 
84
-	public function getMimePart() {
85
-		return $this->data['mimepart'];
86
-	}
84
+    public function getMimePart() {
85
+        return $this->data['mimepart'];
86
+    }
87 87
 
88
-	public function getSize() {
89
-		return $this->data['size'];
90
-	}
88
+    public function getSize() {
89
+        return $this->data['size'];
90
+    }
91 91
 
92
-	public function getMTime() {
93
-		return $this->data['mtime'];
94
-	}
92
+    public function getMTime() {
93
+        return $this->data['mtime'];
94
+    }
95 95
 
96
-	public function getStorageMTime() {
97
-		return $this->data['storage_mtime'];
98
-	}
96
+    public function getStorageMTime() {
97
+        return $this->data['storage_mtime'];
98
+    }
99 99
 
100
-	public function getEtag() {
101
-		return $this->data['etag'];
102
-	}
100
+    public function getEtag() {
101
+        return $this->data['etag'];
102
+    }
103 103
 
104
-	public function getPermissions() {
105
-		return $this->data['permissions'];
106
-	}
104
+    public function getPermissions() {
105
+        return $this->data['permissions'];
106
+    }
107 107
 
108
-	public function isEncrypted() {
109
-		return isset($this->data['encrypted']) && $this->data['encrypted'];
110
-	}
108
+    public function isEncrypted() {
109
+        return isset($this->data['encrypted']) && $this->data['encrypted'];
110
+    }
111 111
 
112
-	public function getMetadataEtag(): ?string {
113
-		return $this->data['metadata_etag'];
114
-	}
112
+    public function getMetadataEtag(): ?string {
113
+        return $this->data['metadata_etag'];
114
+    }
115 115
 
116
-	public function getCreationTime(): ?int {
117
-		return $this->data['creation_time'];
118
-	}
116
+    public function getCreationTime(): ?int {
117
+        return $this->data['creation_time'];
118
+    }
119 119
 
120
-	public function getUploadTime(): ?int {
121
-		return $this->data['upload_time'];
122
-	}
120
+    public function getUploadTime(): ?int {
121
+        return $this->data['upload_time'];
122
+    }
123 123
 
124
-	public function getData() {
125
-		return $this->data;
126
-	}
124
+    public function getData() {
125
+        return $this->data;
126
+    }
127 127
 }
Please login to merge, or discard this patch.
lib/private/Files/Cache/MoveFromCacheTrait.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@
 block discarded – undo
67 67
 		if ($sourceEntry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) {
68 68
 			$folderContent = $sourceCache->getFolderContentsById($sourceEntry->getId());
69 69
 			foreach ($folderContent as $subEntry) {
70
-				$subTargetPath = $targetPath . '/' . $subEntry->getName();
70
+				$subTargetPath = $targetPath.'/'.$subEntry->getName();
71 71
 				$this->copyFromCache($sourceCache, $subEntry, $subTargetPath);
72 72
 			}
73 73
 		}
Please login to merge, or discard this patch.
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -29,63 +29,63 @@
 block discarded – undo
29 29
  * Fallback implementation for moveFromCache
30 30
  */
31 31
 trait MoveFromCacheTrait {
32
-	/**
33
-	 * store meta data for a file or folder
34
-	 *
35
-	 * @param string $file
36
-	 * @param array $data
37
-	 *
38
-	 * @return int file id
39
-	 * @throws \RuntimeException
40
-	 */
41
-	abstract public function put($file, array $data);
32
+    /**
33
+     * store meta data for a file or folder
34
+     *
35
+     * @param string $file
36
+     * @param array $data
37
+     *
38
+     * @return int file id
39
+     * @throws \RuntimeException
40
+     */
41
+    abstract public function put($file, array $data);
42 42
 
43
-	/**
44
-	 * Move a file or folder in the cache
45
-	 *
46
-	 * @param \OCP\Files\Cache\ICache $sourceCache
47
-	 * @param string $sourcePath
48
-	 * @param string $targetPath
49
-	 */
50
-	public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
51
-		$sourceEntry = $sourceCache->get($sourcePath);
43
+    /**
44
+     * Move a file or folder in the cache
45
+     *
46
+     * @param \OCP\Files\Cache\ICache $sourceCache
47
+     * @param string $sourcePath
48
+     * @param string $targetPath
49
+     */
50
+    public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
51
+        $sourceEntry = $sourceCache->get($sourcePath);
52 52
 
53
-		$this->copyFromCache($sourceCache, $sourceEntry, $targetPath);
53
+        $this->copyFromCache($sourceCache, $sourceEntry, $targetPath);
54 54
 
55
-		$sourceCache->remove($sourcePath);
56
-	}
55
+        $sourceCache->remove($sourcePath);
56
+    }
57 57
 
58
-	/**
59
-	 * Copy a file or folder in the cache
60
-	 *
61
-	 * @param \OCP\Files\Cache\ICache $sourceCache
62
-	 * @param ICacheEntry $sourceEntry
63
-	 * @param string $targetPath
64
-	 */
65
-	public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, $targetPath) {
66
-		$this->put($targetPath, $this->cacheEntryToArray($sourceEntry));
67
-		if ($sourceEntry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) {
68
-			$folderContent = $sourceCache->getFolderContentsById($sourceEntry->getId());
69
-			foreach ($folderContent as $subEntry) {
70
-				$subTargetPath = $targetPath . '/' . $subEntry->getName();
71
-				$this->copyFromCache($sourceCache, $subEntry, $subTargetPath);
72
-			}
73
-		}
74
-	}
58
+    /**
59
+     * Copy a file or folder in the cache
60
+     *
61
+     * @param \OCP\Files\Cache\ICache $sourceCache
62
+     * @param ICacheEntry $sourceEntry
63
+     * @param string $targetPath
64
+     */
65
+    public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, $targetPath) {
66
+        $this->put($targetPath, $this->cacheEntryToArray($sourceEntry));
67
+        if ($sourceEntry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) {
68
+            $folderContent = $sourceCache->getFolderContentsById($sourceEntry->getId());
69
+            foreach ($folderContent as $subEntry) {
70
+                $subTargetPath = $targetPath . '/' . $subEntry->getName();
71
+                $this->copyFromCache($sourceCache, $subEntry, $subTargetPath);
72
+            }
73
+        }
74
+    }
75 75
 
76
-	private function cacheEntryToArray(ICacheEntry $entry) {
77
-		return [
78
-			'size' => $entry->getSize(),
79
-			'mtime' => $entry->getMTime(),
80
-			'storage_mtime' => $entry->getStorageMTime(),
81
-			'mimetype' => $entry->getMimeType(),
82
-			'mimepart' => $entry->getMimePart(),
83
-			'etag' => $entry->getEtag(),
84
-			'permissions' => $entry->getPermissions(),
85
-			'encrypted' => $entry->isEncrypted(),
86
-			'creation_time' => $entry->getCreationTime(),
87
-			'upload_time' => $entry->getUploadTime(),
88
-			'metadata_etag' => $entry->getMetadataEtag(),
89
-		];
90
-	}
76
+    private function cacheEntryToArray(ICacheEntry $entry) {
77
+        return [
78
+            'size' => $entry->getSize(),
79
+            'mtime' => $entry->getMTime(),
80
+            'storage_mtime' => $entry->getStorageMTime(),
81
+            'mimetype' => $entry->getMimeType(),
82
+            'mimepart' => $entry->getMimePart(),
83
+            'etag' => $entry->getEtag(),
84
+            'permissions' => $entry->getPermissions(),
85
+            'encrypted' => $entry->isEncrypted(),
86
+            'creation_time' => $entry->getCreationTime(),
87
+            'upload_time' => $entry->getUploadTime(),
88
+            'metadata_etag' => $entry->getMetadataEtag(),
89
+        ];
90
+    }
91 91
 }
Please login to merge, or discard this patch.