Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like View often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use View, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
71 | class View { |
||
72 | /** @var string */ |
||
73 | private $fakeRoot = ''; |
||
74 | |||
75 | /** @var \OC\Files\Cache\Updater */ |
||
76 | protected $updater; |
||
77 | |||
78 | /** |
||
79 | * @var \OCP\Lock\ILockingProvider |
||
80 | */ |
||
81 | private $lockingProvider; |
||
82 | |||
83 | private $lockingEnabled; |
||
84 | |||
85 | /** |
||
86 | * @param string $root |
||
87 | * @throws \Exception If $root contains an invalid path |
||
88 | */ |
||
89 | 1421 | public function __construct($root = '') { |
|
90 | 1421 | if (is_null($root)) { |
|
91 | 1 | throw new \InvalidArgumentException('Root can\'t be null'); |
|
92 | } |
||
93 | 1421 | if (!Filesystem::isValidPath($root)) { |
|
94 | 3 | throw new \Exception(); |
|
95 | } |
||
96 | |||
97 | 1421 | $this->fakeRoot = $root; |
|
98 | |||
99 | 1421 | $this->updater = new Updater($this, Filesystem::getView()); |
|
100 | 1421 | $this->lockingProvider = \OC::$server->getLockingProvider(); |
|
101 | 1421 | $this->lockingEnabled = !($this->lockingProvider instanceof \OC\Lock\NoopLockingProvider); |
|
102 | 1421 | } |
|
103 | |||
104 | 956 | public function getAbsolutePath($path = '/') { |
|
105 | 956 | if ($path === null) { |
|
106 | 3 | return null; |
|
107 | } |
||
108 | 956 | $this->assertPathLength($path); |
|
109 | 956 | if ($path === '') { |
|
110 | 95 | $path = '/'; |
|
111 | 95 | } |
|
112 | 956 | if ($path[0] !== '/') { |
|
113 | 466 | $path = '/' . $path; |
|
114 | 466 | } |
|
115 | 956 | return $this->fakeRoot . $path; |
|
116 | } |
||
117 | |||
118 | /** |
||
119 | * change the root to a fake root |
||
120 | * |
||
121 | * @param string $fakeRoot |
||
122 | * @return boolean|null |
||
123 | */ |
||
124 | 50 | public function chroot($fakeRoot) { |
|
125 | 50 | if (!$fakeRoot == '') { |
|
126 | 48 | if ($fakeRoot[0] !== '/') { |
|
127 | 13 | $fakeRoot = '/' . $fakeRoot; |
|
128 | 13 | } |
|
129 | 48 | } |
|
130 | 50 | $this->fakeRoot = $fakeRoot; |
|
131 | 50 | } |
|
132 | |||
133 | /** |
||
134 | * get the fake root |
||
135 | * |
||
136 | * @return string |
||
137 | */ |
||
138 | 976 | public function getRoot() { |
|
139 | 976 | return $this->fakeRoot; |
|
140 | } |
||
141 | |||
142 | /** |
||
143 | * get path relative to the root of the view |
||
144 | * |
||
145 | * @param string $path |
||
146 | * @return string |
||
147 | */ |
||
148 | 1016 | public function getRelativePath($path) { |
|
149 | 1016 | $this->assertPathLength($path); |
|
150 | 1016 | if ($this->fakeRoot == '') { |
|
151 | 906 | return $path; |
|
152 | } |
||
153 | |||
154 | 1005 | if (rtrim($path, '/') === rtrim($this->fakeRoot, '/')) { |
|
155 | 912 | return '/'; |
|
156 | } |
||
157 | |||
158 | // missing slashes can cause wrong matches! |
||
159 | 1004 | $root = rtrim($this->fakeRoot, '/') . '/'; |
|
160 | |||
161 | 1004 | if (strpos($path, $root) !== 0) { |
|
162 | 1000 | return null; |
|
163 | } else { |
||
164 | 809 | $path = substr($path, strlen($this->fakeRoot)); |
|
165 | 809 | if (strlen($path) === 0) { |
|
166 | return '/'; |
||
167 | } else { |
||
168 | 809 | return $path; |
|
169 | } |
||
170 | } |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * get the mountpoint of the storage object for a path |
||
175 | * ( note: because a storage is not always mounted inside the fakeroot, the |
||
176 | * returned mountpoint is relative to the absolute root of the filesystem |
||
177 | * and does not take the chroot into account ) |
||
178 | * |
||
179 | * @param string $path |
||
180 | * @return string |
||
181 | */ |
||
182 | 1 | public function getMountPoint($path) { |
|
183 | 1 | return Filesystem::getMountPoint($this->getAbsolutePath($path)); |
|
184 | } |
||
185 | |||
186 | /** |
||
187 | * get the mountpoint of the storage object for a path |
||
188 | * ( note: because a storage is not always mounted inside the fakeroot, the |
||
189 | * returned mountpoint is relative to the absolute root of the filesystem |
||
190 | * and does not take the chroot into account ) |
||
191 | * |
||
192 | * @param string $path |
||
193 | * @return \OCP\Files\Mount\IMountPoint |
||
194 | */ |
||
195 | 412 | public function getMount($path) { |
|
196 | 412 | return Filesystem::getMountManager()->find($this->getAbsolutePath($path)); |
|
197 | } |
||
198 | |||
199 | /** |
||
200 | * resolve a path to a storage and internal path |
||
201 | * |
||
202 | * @param string $path |
||
203 | * @return array an array consisting of the storage and the internal path |
||
204 | */ |
||
205 | 832 | public function resolvePath($path) { |
|
206 | 832 | $a = $this->getAbsolutePath($path); |
|
207 | 832 | $p = Filesystem::normalizePath($a); |
|
208 | 832 | return Filesystem::resolvePath($p); |
|
209 | } |
||
210 | |||
211 | /** |
||
212 | * return the path to a local version of the file |
||
213 | * we need this because we can't know if a file is stored local or not from |
||
214 | * outside the filestorage and for some purposes a local file is needed |
||
215 | * |
||
216 | * @param string $path |
||
217 | * @return string |
||
218 | */ |
||
219 | 129 | View Code Duplication | public function getLocalFile($path) { |
220 | 129 | $parent = substr($path, 0, strrpos($path, '/')); |
|
221 | 129 | $path = $this->getAbsolutePath($path); |
|
222 | 128 | list($storage, $internalPath) = Filesystem::resolvePath($path); |
|
223 | 128 | if (Filesystem::isValidPath($parent) and $storage) { |
|
224 | 128 | return $storage->getLocalFile($internalPath); |
|
225 | } else { |
||
226 | return null; |
||
227 | } |
||
228 | } |
||
229 | |||
230 | /** |
||
231 | * @param string $path |
||
232 | * @return string |
||
233 | */ |
||
234 | 1 | View Code Duplication | public function getLocalFolder($path) { |
235 | 1 | $parent = substr($path, 0, strrpos($path, '/')); |
|
236 | 1 | $path = $this->getAbsolutePath($path); |
|
237 | list($storage, $internalPath) = Filesystem::resolvePath($path); |
||
238 | if (Filesystem::isValidPath($parent) and $storage) { |
||
239 | return $storage->getLocalFolder($internalPath); |
||
240 | } else { |
||
241 | return null; |
||
242 | } |
||
243 | } |
||
244 | |||
245 | /** |
||
246 | * the following functions operate with arguments and return values identical |
||
247 | * to those of their PHP built-in equivalents. Mostly they are merely wrappers |
||
248 | * for \OC\Files\Storage\Storage via basicOperation(). |
||
249 | */ |
||
250 | 798 | public function mkdir($path) { |
|
251 | 798 | return $this->basicOperation('mkdir', $path, array('create', 'write')); |
|
252 | } |
||
253 | |||
254 | /** |
||
255 | * remove mount point |
||
256 | * |
||
257 | * @param \OC\Files\Mount\MoveableMount $mount |
||
258 | * @param string $path relative to data/ |
||
259 | * @return boolean |
||
260 | */ |
||
261 | 7 | protected function removeMount($mount, $path) { |
|
262 | 7 | if ($mount instanceof MoveableMount) { |
|
263 | // cut of /user/files to get the relative path to data/user/files |
||
264 | 5 | $pathParts = explode('/', $path, 4); |
|
265 | 5 | $relPath = '/' . $pathParts[3]; |
|
266 | 5 | \OC_Hook::emit( |
|
267 | 5 | Filesystem::CLASSNAME, "umount", |
|
268 | 5 | array(Filesystem::signal_param_path => $relPath) |
|
269 | 5 | ); |
|
270 | 5 | $result = $mount->removeMount(); |
|
271 | 5 | if ($result) { |
|
272 | 5 | \OC_Hook::emit( |
|
273 | 5 | Filesystem::CLASSNAME, "post_umount", |
|
274 | 5 | array(Filesystem::signal_param_path => $relPath) |
|
275 | 5 | ); |
|
276 | 5 | } |
|
277 | 5 | return $result; |
|
278 | } else { |
||
279 | // do not allow deleting the storage's root / the mount point |
||
280 | // because for some storages it might delete the whole contents |
||
281 | // but isn't supposed to work that way |
||
282 | 2 | return false; |
|
283 | } |
||
284 | } |
||
285 | |||
286 | /** |
||
287 | * @param string $path |
||
288 | * @return bool|mixed |
||
289 | */ |
||
290 | 220 | public function rmdir($path) { |
|
291 | 220 | $absolutePath = $this->getAbsolutePath($path); |
|
292 | 218 | $mount = Filesystem::getMountManager()->find($absolutePath); |
|
293 | 218 | if ($mount->getInternalPath($absolutePath) === '') { |
|
294 | 1 | return $this->removeMount($mount, $path); |
|
|
|||
295 | } |
||
296 | 217 | if ($this->is_dir($path)) { |
|
297 | 208 | return $this->basicOperation('rmdir', $path, array('delete')); |
|
298 | } else { |
||
299 | 135 | return false; |
|
300 | } |
||
301 | } |
||
302 | |||
303 | /** |
||
304 | * @param string $path |
||
305 | * @return resource |
||
306 | */ |
||
307 | 303 | public function opendir($path) { |
|
308 | 303 | return $this->basicOperation('opendir', $path, array('read')); |
|
309 | } |
||
310 | |||
311 | /** |
||
312 | * @param $handle |
||
313 | * @return mixed |
||
314 | */ |
||
315 | public function readdir($handle) { |
||
316 | $fsLocal = new Storage\Local(array('datadir' => '/')); |
||
317 | return $fsLocal->readdir($handle); |
||
318 | } |
||
319 | |||
320 | /** |
||
321 | * @param string $path |
||
322 | * @return bool|mixed |
||
323 | */ |
||
324 | 530 | public function is_dir($path) { |
|
325 | 530 | if ($path == '/') { |
|
326 | 299 | return true; |
|
327 | } |
||
328 | 519 | return $this->basicOperation('is_dir', $path); |
|
329 | } |
||
330 | |||
331 | /** |
||
332 | * @param string $path |
||
333 | * @return bool|mixed |
||
334 | */ |
||
335 | 31 | public function is_file($path) { |
|
336 | 31 | if ($path == '/') { |
|
337 | 1 | return false; |
|
338 | } |
||
339 | 31 | return $this->basicOperation('is_file', $path); |
|
340 | } |
||
341 | |||
342 | /** |
||
343 | * @param string $path |
||
344 | * @return mixed |
||
345 | */ |
||
346 | 5 | public function stat($path) { |
|
347 | 5 | return $this->basicOperation('stat', $path); |
|
348 | } |
||
349 | |||
350 | /** |
||
351 | * @param string $path |
||
352 | * @return mixed |
||
353 | */ |
||
354 | 4 | public function filetype($path) { |
|
355 | 4 | return $this->basicOperation('filetype', $path); |
|
356 | } |
||
357 | |||
358 | /** |
||
359 | * @param string $path |
||
360 | * @return mixed |
||
361 | */ |
||
362 | 61 | public function filesize($path) { |
|
363 | 61 | return $this->basicOperation('filesize', $path); |
|
364 | } |
||
365 | |||
366 | /** |
||
367 | * @param string $path |
||
368 | * @return bool|mixed |
||
369 | * @throws \OCP\Files\InvalidPathException |
||
370 | */ |
||
371 | 1 | public function readfile($path) { |
|
372 | 1 | $this->assertPathLength($path); |
|
373 | @ob_end_clean(); |
||
374 | $handle = $this->fopen($path, 'rb'); |
||
375 | if ($handle) { |
||
376 | $chunkSize = 8192; // 8 kB chunks |
||
377 | while (!feof($handle)) { |
||
378 | echo fread($handle, $chunkSize); |
||
379 | flush(); |
||
380 | } |
||
381 | $size = $this->filesize($path); |
||
382 | return $size; |
||
383 | } |
||
384 | return false; |
||
385 | } |
||
386 | |||
387 | /** |
||
388 | * @param string $path |
||
389 | * @return mixed |
||
390 | */ |
||
391 | 18 | public function isCreatable($path) { |
|
392 | 18 | return $this->basicOperation('isCreatable', $path); |
|
393 | } |
||
394 | |||
395 | /** |
||
396 | * @param string $path |
||
397 | * @return mixed |
||
398 | */ |
||
399 | 26 | public function isReadable($path) { |
|
400 | 26 | return $this->basicOperation('isReadable', $path); |
|
401 | } |
||
402 | |||
403 | /** |
||
404 | * @param string $path |
||
405 | * @return mixed |
||
406 | */ |
||
407 | 4 | public function isUpdatable($path) { |
|
408 | 4 | return $this->basicOperation('isUpdatable', $path); |
|
409 | } |
||
410 | |||
411 | /** |
||
412 | * @param string $path |
||
413 | * @return bool|mixed |
||
414 | */ |
||
415 | 4 | public function isDeletable($path) { |
|
416 | 4 | $absolutePath = $this->getAbsolutePath($path); |
|
417 | 3 | $mount = Filesystem::getMountManager()->find($absolutePath); |
|
418 | 3 | if ($mount->getInternalPath($absolutePath) === '') { |
|
419 | return $mount instanceof MoveableMount; |
||
420 | } |
||
421 | 3 | return $this->basicOperation('isDeletable', $path); |
|
422 | } |
||
423 | |||
424 | /** |
||
425 | * @param string $path |
||
426 | * @return mixed |
||
427 | */ |
||
428 | 145 | public function isSharable($path) { |
|
429 | 145 | return $this->basicOperation('isSharable', $path); |
|
430 | } |
||
431 | |||
432 | /** |
||
433 | * @param string $path |
||
434 | * @return bool|mixed |
||
435 | */ |
||
436 | 920 | public function file_exists($path) { |
|
437 | 920 | if ($path == '/') { |
|
438 | 155 | return true; |
|
439 | } |
||
440 | 920 | return $this->basicOperation('file_exists', $path); |
|
441 | } |
||
442 | |||
443 | /** |
||
444 | * @param string $path |
||
445 | * @return mixed |
||
446 | */ |
||
447 | 35 | public function filemtime($path) { |
|
448 | 35 | return $this->basicOperation('filemtime', $path); |
|
449 | } |
||
450 | |||
451 | /** |
||
452 | * @param string $path |
||
453 | * @param int|string $mtime |
||
454 | * @return bool |
||
455 | */ |
||
456 | 509 | public function touch($path, $mtime = null) { |
|
457 | 509 | if (!is_null($mtime) and !is_numeric($mtime)) { |
|
458 | $mtime = strtotime($mtime); |
||
459 | } |
||
460 | |||
461 | 509 | $hooks = array('touch'); |
|
462 | |||
463 | 509 | if (!$this->file_exists($path)) { |
|
464 | 502 | $hooks[] = 'create'; |
|
465 | 502 | $hooks[] = 'write'; |
|
466 | 502 | } |
|
467 | 509 | $result = $this->basicOperation('touch', $path, $hooks, $mtime); |
|
468 | 509 | if (!$result) { |
|
469 | // If create file fails because of permissions on external storage like SMB folders, |
||
470 | // check file exists and return false if not. |
||
471 | 4 | if (!$this->file_exists($path)) { |
|
472 | 2 | return false; |
|
473 | } |
||
474 | 2 | if (is_null($mtime)) { |
|
475 | $mtime = time(); |
||
476 | } |
||
477 | //if native touch fails, we emulate it by changing the mtime in the cache |
||
478 | 2 | $this->putFileInfo($path, array('mtime' => $mtime)); |
|
479 | 2 | } |
|
480 | 509 | return true; |
|
481 | } |
||
482 | |||
483 | /** |
||
484 | * @param string $path |
||
485 | * @return mixed |
||
486 | */ |
||
487 | 97 | public function file_get_contents($path) { |
|
488 | 97 | return $this->basicOperation('file_get_contents', $path, array('read')); |
|
489 | } |
||
490 | |||
491 | /** |
||
492 | * @param bool $exists |
||
493 | * @param string $path |
||
494 | * @param bool $run |
||
495 | */ |
||
496 | 7 | protected function emit_file_hooks_pre($exists, $path, &$run) { |
|
497 | 7 | View Code Duplication | if (!$exists) { |
498 | 7 | \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_create, array( |
|
499 | 7 | Filesystem::signal_param_path => $this->getHookPath($path), |
|
500 | 7 | Filesystem::signal_param_run => &$run, |
|
501 | 7 | )); |
|
502 | 7 | } else { |
|
503 | \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_update, array( |
||
504 | Filesystem::signal_param_path => $this->getHookPath($path), |
||
505 | Filesystem::signal_param_run => &$run, |
||
506 | )); |
||
507 | } |
||
508 | 7 | \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_write, array( |
|
509 | 7 | Filesystem::signal_param_path => $this->getHookPath($path), |
|
510 | 7 | Filesystem::signal_param_run => &$run, |
|
511 | 7 | )); |
|
512 | 7 | } |
|
513 | |||
514 | /** |
||
515 | * @param bool $exists |
||
516 | * @param string $path |
||
517 | */ |
||
518 | 8 | protected function emit_file_hooks_post($exists, $path) { |
|
519 | 8 | View Code Duplication | if (!$exists) { |
520 | 7 | \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_post_create, array( |
|
521 | 7 | Filesystem::signal_param_path => $this->getHookPath($path), |
|
522 | 7 | )); |
|
523 | 7 | } else { |
|
524 | 1 | \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_post_update, array( |
|
525 | 1 | Filesystem::signal_param_path => $this->getHookPath($path), |
|
526 | 1 | )); |
|
527 | } |
||
528 | 8 | \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_post_write, array( |
|
529 | 8 | Filesystem::signal_param_path => $this->getHookPath($path), |
|
530 | 8 | )); |
|
531 | 8 | } |
|
532 | |||
533 | /** |
||
534 | * @param string $path |
||
535 | * @param mixed $data |
||
536 | * @return bool|mixed |
||
537 | */ |
||
538 | 442 | public function file_put_contents($path, $data) { |
|
539 | 442 | if (is_resource($data)) { //not having to deal with streams in file_put_contents makes life easier |
|
540 | 10 | $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); |
|
541 | 10 | if (Filesystem::isValidPath($path) |
|
542 | 10 | and !Filesystem::isFileBlacklisted($path) |
|
543 | 10 | ) { |
|
544 | 10 | $path = $this->getRelativePath($absolutePath); |
|
545 | |||
546 | 10 | $this->lockFile($path, ILockingProvider::LOCK_SHARED); |
|
547 | |||
548 | 10 | $exists = $this->file_exists($path); |
|
549 | 10 | $run = true; |
|
550 | 10 | if ($this->shouldEmitHooks($path)) { |
|
551 | 1 | $this->emit_file_hooks_pre($exists, $path, $run); |
|
552 | 1 | } |
|
553 | 10 | if (!$run) { |
|
554 | $this->unlockFile($path, ILockingProvider::LOCK_SHARED); |
||
555 | return false; |
||
556 | } |
||
557 | |||
558 | 10 | $this->changeLock($path, ILockingProvider::LOCK_EXCLUSIVE); |
|
559 | |||
560 | /** @var \OC\Files\Storage\Storage $storage */ |
||
561 | 10 | list($storage, $internalPath) = $this->resolvePath($path); |
|
562 | 10 | $target = $storage->fopen($internalPath, 'w'); |
|
563 | 10 | if ($target) { |
|
564 | 10 | list (, $result) = \OC_Helper::streamCopy($data, $target); |
|
565 | 10 | fclose($target); |
|
566 | 10 | fclose($data); |
|
567 | |||
568 | 10 | $this->updater->update($path); |
|
569 | |||
570 | 10 | $this->changeLock($path, ILockingProvider::LOCK_SHARED); |
|
571 | |||
572 | 10 | if ($this->shouldEmitHooks($path) && $result !== false) { |
|
573 | 1 | $this->emit_file_hooks_post($exists, $path); |
|
574 | 1 | } |
|
575 | 10 | $this->unlockFile($path, ILockingProvider::LOCK_SHARED); |
|
576 | 10 | return $result; |
|
577 | } else { |
||
578 | $this->unlockFile($path, ILockingProvider::LOCK_EXCLUSIVE); |
||
579 | return false; |
||
580 | } |
||
581 | } else { |
||
582 | return false; |
||
583 | } |
||
584 | } else { |
||
585 | 437 | $hooks = ($this->file_exists($path)) ? array('update', 'write') : array('create', 'write'); |
|
586 | 436 | return $this->basicOperation('file_put_contents', $path, $hooks, $data); |
|
587 | } |
||
588 | } |
||
589 | |||
590 | /** |
||
591 | * @param string $path |
||
592 | * @return bool|mixed |
||
593 | */ |
||
594 | 139 | public function unlink($path) { |
|
595 | 139 | if ($path === '' || $path === '/') { |
|
596 | // do not allow deleting the root |
||
597 | 1 | return false; |
|
598 | } |
||
599 | 139 | $postFix = (substr($path, -1, 1) === '/') ? '/' : ''; |
|
600 | 139 | $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); |
|
601 | 138 | $mount = Filesystem::getMountManager()->find($absolutePath . $postFix); |
|
602 | 138 | if ($mount and $mount->getInternalPath($absolutePath) === '') { |
|
603 | 6 | return $this->removeMount($mount, $absolutePath); |
|
604 | } |
||
605 | 136 | return $this->basicOperation('unlink', $path, array('delete')); |
|
606 | } |
||
607 | |||
608 | /** |
||
609 | * @param string $directory |
||
610 | * @return bool|mixed |
||
611 | */ |
||
612 | 207 | public function deleteAll($directory) { |
|
613 | 207 | return $this->rmdir($directory); |
|
614 | } |
||
615 | |||
616 | /** |
||
617 | * Rename/move a file or folder from the source path to target path. |
||
618 | * |
||
619 | * @param string $path1 source path |
||
620 | * @param string $path2 target path |
||
621 | * |
||
622 | * @return bool|mixed |
||
623 | */ |
||
624 | 116 | public function rename($path1, $path2) { |
|
625 | 116 | $absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1)); |
|
626 | 115 | $absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($path2)); |
|
627 | 115 | $result = false; |
|
628 | if ( |
||
629 | 115 | Filesystem::isValidPath($path2) |
|
630 | 115 | and Filesystem::isValidPath($path1) |
|
631 | 115 | and !Filesystem::isFileBlacklisted($path2) |
|
632 | 115 | ) { |
|
633 | 115 | $path1 = $this->getRelativePath($absolutePath1); |
|
634 | 115 | $path2 = $this->getRelativePath($absolutePath2); |
|
635 | 115 | $exists = $this->file_exists($path2); |
|
636 | |||
637 | 115 | if ($path1 == null or $path2 == null) { |
|
638 | return false; |
||
639 | } |
||
640 | |||
641 | 115 | $this->lockFile($path1, ILockingProvider::LOCK_SHARED, true); |
|
642 | try { |
||
643 | 115 | $this->lockFile($path2, ILockingProvider::LOCK_SHARED, true); |
|
644 | 115 | } catch (LockedException $e) { |
|
645 | 1 | $this->unlockFile($path1, ILockingProvider::LOCK_SHARED); |
|
646 | 1 | throw $e; |
|
647 | } |
||
648 | |||
649 | 114 | $run = true; |
|
650 | 114 | if ($this->shouldEmitHooks($path1) && (Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2))) { |
|
651 | // if it was a rename from a part file to a regular file it was a write and not a rename operation |
||
652 | $this->emit_file_hooks_pre($exists, $path2, $run); |
||
653 | 114 | } elseif ($this->shouldEmitHooks($path1)) { |
|
654 | 66 | \OC_Hook::emit( |
|
655 | 66 | Filesystem::CLASSNAME, Filesystem::signal_rename, |
|
656 | array( |
||
657 | 66 | Filesystem::signal_param_oldpath => $this->getHookPath($path1), |
|
658 | 66 | Filesystem::signal_param_newpath => $this->getHookPath($path2), |
|
659 | 66 | Filesystem::signal_param_run => &$run |
|
660 | 66 | ) |
|
661 | 66 | ); |
|
662 | 66 | } |
|
663 | 114 | if ($run) { |
|
664 | 114 | $this->verifyPath(dirname($path2), basename($path2)); |
|
665 | |||
666 | 114 | $manager = Filesystem::getMountManager(); |
|
667 | 114 | $mount1 = $this->getMount($path1); |
|
668 | 114 | $mount2 = $this->getMount($path2); |
|
669 | 114 | $storage1 = $mount1->getStorage(); |
|
670 | 114 | $storage2 = $mount2->getStorage(); |
|
671 | 114 | $internalPath1 = $mount1->getInternalPath($absolutePath1); |
|
672 | 114 | $internalPath2 = $mount2->getInternalPath($absolutePath2); |
|
673 | |||
674 | 114 | $this->changeLock($path1, ILockingProvider::LOCK_EXCLUSIVE, true); |
|
675 | 113 | $this->changeLock($path2, ILockingProvider::LOCK_EXCLUSIVE, true); |
|
676 | |||
677 | 113 | if ($internalPath1 === '' and $mount1 instanceof MoveableMount) { |
|
678 | 46 | if ($this->isTargetAllowed($absolutePath2)) { |
|
679 | /** |
||
680 | * @var \OC\Files\Mount\MountPoint | \OC\Files\Mount\MoveableMount $mount1 |
||
681 | */ |
||
682 | 44 | $sourceMountPoint = $mount1->getMountPoint(); |
|
683 | 44 | $result = $mount1->moveMount($absolutePath2); |
|
684 | 44 | $manager->moveMount($sourceMountPoint, $mount1->getMountPoint()); |
|
685 | 44 | } else { |
|
686 | 2 | $result = false; |
|
687 | } |
||
688 | // moving a file/folder within the same mount point |
||
689 | 113 | } elseif ($storage1 == $storage2) { |
|
690 | 72 | if ($storage1) { |
|
691 | 72 | $result = $storage1->rename($internalPath1, $internalPath2); |
|
692 | 72 | } else { |
|
693 | $result = false; |
||
694 | } |
||
695 | // moving a file/folder between storages (from $storage1 to $storage2) |
||
696 | 72 | } else { |
|
697 | 14 | $result = $storage2->moveFromStorage($storage1, $internalPath1, $internalPath2); |
|
698 | } |
||
699 | |||
700 | 113 | if ((Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2)) && $result !== false) { |
|
701 | // if it was a rename from a part file to a regular file it was a write and not a rename operation |
||
702 | 29 | $this->updater->update($path2); |
|
703 | 113 | } else if ($result) { |
|
704 | 79 | if ($internalPath1 !== '') { // dont do a cache update for moved mounts |
|
705 | 49 | $this->updater->rename($path1, $path2); |
|
706 | 49 | } else { // only do etag propagation |
|
707 | 44 | $this->getUpdater()->getPropagator()->addChange($path1); |
|
708 | 44 | $this->getUpdater()->getPropagator()->addChange($path2); |
|
709 | 44 | $this->getUpdater()->getPropagator()->propagateChanges(); |
|
710 | } |
||
711 | 79 | } |
|
712 | |||
713 | 113 | $this->changeLock($path1, ILockingProvider::LOCK_SHARED, true); |
|
714 | 113 | $this->changeLock($path2, ILockingProvider::LOCK_SHARED, true); |
|
715 | |||
716 | 113 | if ((Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2)) && $result !== false) { |
|
717 | 29 | if ($this->shouldEmitHooks()) { |
|
718 | 2 | $this->emit_file_hooks_post($exists, $path2); |
|
719 | 2 | } |
|
720 | 113 | } elseif ($result) { |
|
721 | 79 | if ($this->shouldEmitHooks($path1) and $this->shouldEmitHooks($path2)) { |
|
722 | 60 | \OC_Hook::emit( |
|
723 | 60 | Filesystem::CLASSNAME, |
|
724 | 60 | Filesystem::signal_post_rename, |
|
725 | array( |
||
726 | 60 | Filesystem::signal_param_oldpath => $this->getHookPath($path1), |
|
727 | 60 | Filesystem::signal_param_newpath => $this->getHookPath($path2) |
|
728 | 60 | ) |
|
729 | 60 | ); |
|
730 | 60 | } |
|
731 | 79 | } |
|
732 | 113 | } |
|
733 | 113 | $this->unlockFile($path1, ILockingProvider::LOCK_SHARED, true); |
|
734 | 113 | $this->unlockFile($path2, ILockingProvider::LOCK_SHARED, true); |
|
735 | 113 | } |
|
736 | 113 | return $result; |
|
737 | } |
||
738 | |||
739 | /** |
||
740 | * Copy a file/folder from the source path to target path |
||
741 | * |
||
742 | * @param string $path1 source path |
||
743 | * @param string $path2 target path |
||
744 | * @param bool $preserveMtime whether to preserve mtime on the copy |
||
745 | * |
||
746 | * @return bool|mixed |
||
747 | */ |
||
748 | 25 | public function copy($path1, $path2, $preserveMtime = false) { |
|
749 | 25 | $absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1)); |
|
750 | 24 | $absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($path2)); |
|
751 | 24 | $result = false; |
|
752 | if ( |
||
753 | 24 | Filesystem::isValidPath($path2) |
|
754 | 24 | and Filesystem::isValidPath($path1) |
|
755 | 24 | and !Filesystem::isFileBlacklisted($path2) |
|
756 | 24 | ) { |
|
757 | 24 | $path1 = $this->getRelativePath($absolutePath1); |
|
758 | 24 | $path2 = $this->getRelativePath($absolutePath2); |
|
759 | |||
760 | 24 | if ($path1 == null or $path2 == null) { |
|
761 | return false; |
||
762 | } |
||
763 | 24 | $run = true; |
|
764 | |||
765 | 24 | $this->lockFile($path2, ILockingProvider::LOCK_SHARED); |
|
766 | 24 | $this->lockFile($path1, ILockingProvider::LOCK_SHARED); |
|
767 | 24 | $lockTypePath1 = ILockingProvider::LOCK_SHARED; |
|
768 | 24 | $lockTypePath2 = ILockingProvider::LOCK_SHARED; |
|
769 | |||
770 | try { |
||
771 | |||
772 | 24 | $exists = $this->file_exists($path2); |
|
773 | 24 | View Code Duplication | if ($this->shouldEmitHooks()) { |
774 | 6 | \OC_Hook::emit( |
|
775 | 6 | Filesystem::CLASSNAME, |
|
776 | 6 | Filesystem::signal_copy, |
|
777 | array( |
||
778 | 6 | Filesystem::signal_param_oldpath => $this->getHookPath($path1), |
|
779 | 6 | Filesystem::signal_param_newpath => $this->getHookPath($path2), |
|
780 | 6 | Filesystem::signal_param_run => &$run |
|
781 | 6 | ) |
|
782 | 6 | ); |
|
783 | 6 | $this->emit_file_hooks_pre($exists, $path2, $run); |
|
784 | 6 | } |
|
785 | 24 | if ($run) { |
|
786 | 24 | $mount1 = $this->getMount($path1); |
|
787 | 24 | $mount2 = $this->getMount($path2); |
|
788 | 24 | $storage1 = $mount1->getStorage(); |
|
789 | 24 | $internalPath1 = $mount1->getInternalPath($absolutePath1); |
|
790 | 24 | $storage2 = $mount2->getStorage(); |
|
791 | 24 | $internalPath2 = $mount2->getInternalPath($absolutePath2); |
|
792 | |||
793 | 24 | $this->changeLock($path2, ILockingProvider::LOCK_EXCLUSIVE); |
|
794 | 24 | $lockTypePath2 = ILockingProvider::LOCK_EXCLUSIVE; |
|
795 | |||
796 | 24 | if ($mount1->getMountPoint() == $mount2->getMountPoint()) { |
|
797 | 16 | if ($storage1) { |
|
798 | 16 | $result = $storage1->copy($internalPath1, $internalPath2); |
|
799 | 15 | } else { |
|
800 | $result = false; |
||
801 | } |
||
802 | 15 | } else { |
|
803 | 10 | $result = $storage2->copyFromStorage($storage1, $internalPath1, $internalPath2); |
|
804 | } |
||
805 | |||
806 | 23 | $this->updater->update($path2); |
|
807 | |||
808 | 23 | $this->changeLock($path2, ILockingProvider::LOCK_SHARED); |
|
809 | 23 | $lockTypePath2 = ILockingProvider::LOCK_SHARED; |
|
810 | |||
811 | 23 | View Code Duplication | if ($this->shouldEmitHooks() && $result !== false) { |
812 | 5 | \OC_Hook::emit( |
|
813 | 5 | Filesystem::CLASSNAME, |
|
814 | 5 | Filesystem::signal_post_copy, |
|
815 | array( |
||
816 | 5 | Filesystem::signal_param_oldpath => $this->getHookPath($path1), |
|
817 | 5 | Filesystem::signal_param_newpath => $this->getHookPath($path2) |
|
818 | 5 | ) |
|
819 | 5 | ); |
|
820 | 5 | $this->emit_file_hooks_post($exists, $path2); |
|
821 | 5 | } |
|
822 | |||
823 | 23 | } |
|
824 | 24 | } catch (\Exception $e) { |
|
825 | 1 | $this->unlockFile($path2, $lockTypePath2); |
|
826 | 1 | $this->unlockFile($path1, $lockTypePath1); |
|
827 | 1 | throw $e; |
|
828 | } |
||
829 | |||
830 | 23 | $this->unlockFile($path2, $lockTypePath2); |
|
831 | 23 | $this->unlockFile($path1, $lockTypePath1); |
|
832 | |||
833 | 23 | } |
|
834 | 23 | return $result; |
|
835 | } |
||
836 | |||
837 | /** |
||
838 | * @param string $path |
||
839 | * @param string $mode |
||
840 | * @return resource |
||
841 | */ |
||
842 | 568 | public function fopen($path, $mode) { |
|
843 | 568 | $hooks = array(); |
|
844 | switch ($mode) { |
||
845 | 568 | case 'r': |
|
846 | 568 | case 'rb': |
|
847 | 91 | $hooks[] = 'read'; |
|
848 | 91 | break; |
|
849 | 502 | case 'r+': |
|
850 | 502 | case 'rb+': |
|
851 | 502 | case 'w+': |
|
852 | 502 | case 'wb+': |
|
853 | 502 | case 'x+': |
|
854 | 502 | case 'xb+': |
|
855 | 502 | case 'a+': |
|
856 | 502 | case 'ab+': |
|
857 | $hooks[] = 'read'; |
||
858 | $hooks[] = 'write'; |
||
859 | break; |
||
860 | 502 | case 'w': |
|
861 | 502 | case 'wb': |
|
862 | 502 | case 'x': |
|
863 | 502 | case 'xb': |
|
864 | 502 | case 'a': |
|
865 | 502 | case 'ab': |
|
866 | 502 | $hooks[] = 'write'; |
|
867 | 502 | break; |
|
868 | default: |
||
869 | \OCP\Util::writeLog('core', 'invalid mode (' . $mode . ') for ' . $path, \OCP\Util::ERROR); |
||
870 | } |
||
871 | |||
872 | 568 | return $this->basicOperation('fopen', $path, $hooks, $mode); |
|
873 | } |
||
874 | |||
875 | /** |
||
876 | * @param string $path |
||
877 | * @return bool|string |
||
878 | * @throws \OCP\Files\InvalidPathException |
||
879 | */ |
||
880 | 49 | public function toTmpFile($path) { |
|
881 | 49 | $this->assertPathLength($path); |
|
882 | 48 | if (Filesystem::isValidPath($path)) { |
|
883 | 48 | $source = $this->fopen($path, 'r'); |
|
884 | 48 | if ($source) { |
|
885 | 48 | $extension = pathinfo($path, PATHINFO_EXTENSION); |
|
886 | 48 | $tmpFile = \OC_Helper::tmpFile($extension); |
|
887 | 48 | file_put_contents($tmpFile, $source); |
|
888 | 48 | return $tmpFile; |
|
889 | } else { |
||
890 | return false; |
||
891 | } |
||
892 | } else { |
||
893 | return false; |
||
894 | } |
||
895 | } |
||
896 | |||
897 | /** |
||
898 | * @param string $tmpFile |
||
899 | * @param string $path |
||
900 | * @return bool|mixed |
||
901 | * @throws \OCP\Files\InvalidPathException |
||
902 | */ |
||
903 | 1 | public function fromTmpFile($tmpFile, $path) { |
|
904 | 1 | $this->assertPathLength($path); |
|
905 | if (Filesystem::isValidPath($path)) { |
||
906 | |||
907 | // Get directory that the file is going into |
||
908 | $filePath = dirname($path); |
||
909 | |||
910 | // Create the directories if any |
||
911 | if (!$this->file_exists($filePath)) { |
||
912 | $this->mkdir($filePath); |
||
913 | } |
||
914 | |||
915 | $source = fopen($tmpFile, 'r'); |
||
916 | if ($source) { |
||
917 | $result = $this->file_put_contents($path, $source); |
||
918 | // $this->file_put_contents() might have already closed |
||
919 | // the resource, so we check it, before trying to close it |
||
920 | // to avoid messages in the error log. |
||
921 | if (is_resource($source)) { |
||
922 | fclose($source); |
||
923 | } |
||
924 | unlink($tmpFile); |
||
925 | return $result; |
||
926 | } else { |
||
927 | return false; |
||
928 | } |
||
929 | } else { |
||
930 | return false; |
||
931 | } |
||
932 | } |
||
933 | |||
934 | |||
935 | /** |
||
936 | * @param string $path |
||
937 | * @return mixed |
||
938 | * @throws \OCP\Files\InvalidPathException |
||
939 | */ |
||
940 | 2 | public function getMimeType($path) { |
|
944 | |||
945 | /** |
||
946 | * @param string $type |
||
947 | * @param string $path |
||
948 | * @param bool $raw |
||
949 | * @return bool|null|string |
||
950 | */ |
||
951 | 1 | public function hash($type, $path, $raw = false) { |
|
952 | 1 | $postFix = (substr($path, -1, 1) === '/') ? '/' : ''; |
|
953 | 1 | $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); |
|
954 | if (Filesystem::isValidPath($path)) { |
||
955 | $path = $this->getRelativePath($absolutePath); |
||
956 | if ($path == null) { |
||
957 | return false; |
||
958 | } |
||
959 | if ($this->shouldEmitHooks($path)) { |
||
960 | \OC_Hook::emit( |
||
961 | Filesystem::CLASSNAME, |
||
962 | Filesystem::signal_read, |
||
963 | array(Filesystem::signal_param_path => $this->getHookPath($path)) |
||
964 | ); |
||
965 | } |
||
966 | list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix); |
||
967 | if ($storage) { |
||
968 | $result = $storage->hash($type, $internalPath, $raw); |
||
969 | return $result; |
||
970 | } |
||
971 | } |
||
972 | return null; |
||
973 | } |
||
974 | |||
975 | /** |
||
976 | * @param string $path |
||
977 | * @return mixed |
||
978 | * @throws \OCP\Files\InvalidPathException |
||
979 | */ |
||
980 | 48 | public function free_space($path = '/') { |
|
984 | |||
985 | /** |
||
986 | * abstraction layer for basic filesystem functions: wrapper for \OC\Files\Storage\Storage |
||
987 | * |
||
988 | * @param string $operation |
||
989 | * @param string $path |
||
990 | * @param array $hooks (optional) |
||
991 | * @param mixed $extraParam (optional) |
||
992 | * @return mixed |
||
993 | * |
||
994 | * This method takes requests for basic filesystem functions (e.g. reading & writing |
||
995 | * files), processes hooks and proxies, sanitises paths, and finally passes them on to |
||
996 | * \OC\Files\Storage\Storage for delegation to a storage backend for execution |
||
997 | */ |
||
998 | 927 | private function basicOperation($operation, $path, $hooks = array(), $extraParam = null) { |
|
999 | 927 | $postFix = (substr($path, -1, 1) === '/') ? '/' : ''; |
|
1000 | 927 | $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); |
|
1001 | 927 | if (Filesystem::isValidPath($path) |
|
1002 | 927 | and !Filesystem::isFileBlacklisted($path) |
|
1003 | 927 | ) { |
|
1004 | 927 | $path = $this->getRelativePath($absolutePath); |
|
1005 | 927 | if ($path == null) { |
|
1006 | 13 | return false; |
|
1007 | } |
||
1008 | |||
1009 | 927 | if (in_array('write', $hooks) || in_array('delete', $hooks) || in_array('read', $hooks)) { |
|
1010 | // always a shared lock during pre-hooks so the hook can read the file |
||
1011 | 926 | $this->lockFile($path, ILockingProvider::LOCK_SHARED); |
|
1012 | 926 | } |
|
1013 | |||
1014 | 927 | $run = $this->runHooks($hooks, $path); |
|
1015 | 927 | list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix); |
|
1016 | 927 | if ($run and $storage) { |
|
1017 | 927 | if (in_array('write', $hooks) || in_array('delete', $hooks)) { |
|
1018 | 817 | $this->changeLock($path, ILockingProvider::LOCK_EXCLUSIVE); |
|
1019 | 817 | } |
|
1020 | try { |
||
1021 | 927 | if (!is_null($extraParam)) { |
|
1022 | 798 | $result = $storage->$operation($internalPath, $extraParam); |
|
1023 | 798 | } else { |
|
1024 | 927 | $result = $storage->$operation($internalPath); |
|
1025 | } |
||
1079 | |||
1080 | /** |
||
1081 | * get the path relative to the default root for hook usage |
||
1082 | * |
||
1083 | * @param string $path |
||
1084 | * @return string |
||
1085 | */ |
||
1086 | 927 | private function getHookPath($path) { |
|
1092 | |||
1093 | 927 | private function shouldEmitHooks($path = '') { |
|
1115 | |||
1116 | /** |
||
1117 | * @param string[] $hooks |
||
1118 | * @param string $path |
||
1119 | * @param bool $post |
||
1120 | * @return bool |
||
1121 | */ |
||
1122 | 927 | private function runHooks($hooks, $path, $post = false) { |
|
1151 | |||
1152 | /** |
||
1153 | * check if a file or folder has been updated since $time |
||
1154 | * |
||
1155 | * @param string $path |
||
1156 | * @param int $time |
||
1157 | * @return bool |
||
1158 | */ |
||
1159 | 1 | public function hasUpdated($path, $time) { |
|
1162 | |||
1163 | /** |
||
1164 | * get the filesystem info |
||
1165 | * |
||
1166 | * @param string $path |
||
1167 | * @param boolean|string $includeMountPoints true to add mountpoint sizes, |
||
1168 | * 'ext' to add only ext storage mount point sizes. Defaults to true. |
||
1169 | * defaults to true |
||
1170 | * @return \OC\Files\FileInfo|false |
||
1171 | */ |
||
1172 | 810 | public function getFileInfo($path, $includeMountPoints = true) { |
|
1252 | |||
1253 | /** |
||
1254 | * get the content of a directory |
||
1255 | * |
||
1256 | * @param string $directory path under datadirectory |
||
1257 | * @param string $mimetype_filter limit returned content to this mimetype or mimepart |
||
1258 | * @return FileInfo[] |
||
1259 | */ |
||
1260 | 200 | public function getDirectoryContent($directory, $mimetype_filter = '') { |
|
1410 | |||
1411 | /** |
||
1412 | * change file metadata |
||
1413 | * |
||
1414 | * @param string $path |
||
1415 | * @param array|\OCP\Files\FileInfo $data |
||
1416 | * @return int |
||
1417 | * |
||
1418 | * returns the fileid of the updated file |
||
1419 | */ |
||
1420 | 32 | public function putFileInfo($path, $data) { |
|
1444 | |||
1445 | /** |
||
1446 | * search for files with the name matching $query |
||
1447 | * |
||
1448 | * @param string $query |
||
1449 | * @return FileInfo[] |
||
1450 | */ |
||
1451 | 2 | public function search($query) { |
|
1454 | |||
1455 | /** |
||
1456 | * search for files with the name matching $query |
||
1457 | * |
||
1458 | * @param string $query |
||
1459 | * @return FileInfo[] |
||
1460 | */ |
||
1461 | 10 | public function searchRaw($query) { |
|
1464 | |||
1465 | /** |
||
1466 | * search for files by mimetype |
||
1467 | * |
||
1468 | * @param string $mimetype |
||
1469 | * @return FileInfo[] |
||
1470 | */ |
||
1471 | 1 | public function searchByMime($mimetype) { |
|
1474 | |||
1475 | /** |
||
1476 | * search for files by tag |
||
1477 | * |
||
1478 | * @param string|int $tag name or tag id |
||
1479 | * @param string $userId owner of the tags |
||
1480 | * @return FileInfo[] |
||
1481 | */ |
||
1482 | public function searchByTag($tag, $userId) { |
||
1485 | |||
1486 | /** |
||
1487 | * @param string $method cache method |
||
1488 | * @param array $args |
||
1489 | * @return FileInfo[] |
||
1490 | */ |
||
1491 | 12 | private function searchCommon($method, $args) { |
|
1533 | |||
1534 | /** |
||
1535 | * Get the owner for a file or folder |
||
1536 | * |
||
1537 | * @param string $path |
||
1538 | * @return string |
||
1539 | */ |
||
1540 | 76 | public function getOwner($path) { |
|
1543 | |||
1544 | /** |
||
1545 | * get the ETag for a file or folder |
||
1546 | * |
||
1547 | * @param string $path |
||
1548 | * @return string |
||
1549 | */ |
||
1550 | 28 | public function getETag($path) { |
|
1562 | |||
1563 | /** |
||
1564 | * Get the path of a file by id, relative to the view |
||
1565 | * |
||
1566 | * Note that the resulting path is not guarantied to be unique for the id, multiple paths can point to the same file |
||
1567 | * |
||
1568 | * @param int $id |
||
1569 | * @return string|null |
||
1570 | */ |
||
1571 | 147 | public function getPath($id) { |
|
1596 | |||
1597 | 1037 | private function assertPathLength($path) { |
|
1606 | |||
1607 | /** |
||
1608 | * check if it is allowed to move a mount point to a given target. |
||
1609 | * It is not allowed to move a mount point into a different mount point or |
||
1610 | * into an already shared folder |
||
1611 | * |
||
1612 | * @param string $target path |
||
1613 | * @return boolean |
||
1614 | */ |
||
1615 | 46 | private function isTargetAllowed($target) { |
|
1650 | |||
1651 | /** |
||
1652 | * Get a fileinfo object for files that are ignored in the cache (part files) |
||
1653 | * |
||
1654 | * @param string $path |
||
1655 | * @return \OCP\Files\FileInfo |
||
1656 | */ |
||
1657 | 1 | private function getPartFileInfo($path) { |
|
1678 | |||
1679 | /** |
||
1680 | * @return Updater |
||
1681 | */ |
||
1682 | 422 | public function getUpdater() { |
|
1685 | |||
1686 | /** |
||
1687 | * @param string $path |
||
1688 | * @param string $fileName |
||
1689 | * @throws InvalidPathException |
||
1690 | */ |
||
1691 | 166 | public function verifyPath($path, $fileName) { |
|
1725 | |||
1726 | /** |
||
1727 | * get all parent folders of $path |
||
1728 | * |
||
1729 | * @param string $path |
||
1730 | * @return string[] |
||
1731 | */ |
||
1732 | 810 | private function getParents($path) { |
|
1752 | |||
1753 | /** |
||
1754 | * Returns the mount point for which to lock |
||
1755 | * |
||
1756 | * @param string $absolutePath absolute path |
||
1757 | * @param bool $useParentMount true to return parent mount instead of whatever |
||
1758 | * is mounted directly on the given path, false otherwise |
||
1759 | * @return \OC\Files\Mount\MountPoint mount point for which to apply locks |
||
1760 | */ |
||
1761 | 810 | private function getMountForLock($absolutePath, $useParentMount = false) { |
|
1779 | |||
1780 | /** |
||
1781 | * Lock the given path |
||
1782 | * |
||
1783 | * @param string $path the path of the file to lock, relative to the view |
||
1784 | * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
||
1785 | * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage |
||
1786 | * |
||
1787 | * @return bool False if the path is excluded from locking, true otherwise |
||
1788 | * @throws \OCP\Lock\LockedException if the path is already locked |
||
1789 | */ |
||
1790 | 810 | View Code Duplication | private function lockPath($path, $type, $lockMountPoint = false) { |
1816 | |||
1817 | /** |
||
1818 | * Change the lock type |
||
1819 | * |
||
1820 | * @param string $path the path of the file to lock, relative to the view |
||
1821 | * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
||
1822 | * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage |
||
1823 | * |
||
1824 | * @return bool False if the path is excluded from locking, true otherwise |
||
1825 | * @throws \OCP\Lock\LockedException if the path is already locked |
||
1826 | */ |
||
1827 | 818 | View Code Duplication | public function changeLock($path, $type, $lockMountPoint = false) { |
1854 | |||
1855 | /** |
||
1856 | * Unlock the given path |
||
1857 | * |
||
1858 | * @param string $path the path of the file to unlock, relative to the view |
||
1859 | * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
||
1860 | * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage |
||
1861 | * |
||
1862 | * @return bool False if the path is excluded from locking, true otherwise |
||
1863 | */ |
||
1864 | 810 | View Code Duplication | private function unlockPath($path, $type, $lockMountPoint = false) { |
1882 | |||
1883 | /** |
||
1884 | * Lock a path and all its parents up to the root of the view |
||
1885 | * |
||
1886 | * @param string $path the path of the file to lock relative to the view |
||
1887 | * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
||
1888 | * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage |
||
1889 | * |
||
1890 | * @return bool False if the path is excluded from locking, true otherwise |
||
1891 | */ |
||
1892 | 936 | View Code Duplication | public function lockFile($path, $type, $lockMountPoint = false) { |
1908 | |||
1909 | /** |
||
1910 | * Unlock a path and all its parents up to the root of the view |
||
1911 | * |
||
1912 | * @param string $path the path of the file to lock relative to the view |
||
1913 | * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
||
1914 | * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage |
||
1915 | * |
||
1916 | * @return bool False if the path is excluded from locking, true otherwise |
||
1917 | */ |
||
1918 | 936 | View Code Duplication | public function unlockFile($path, $type, $lockMountPoint = false) { |
1934 | |||
1935 | /** |
||
1936 | * Only lock files in data/user/files/ |
||
1937 | * |
||
1938 | * @param string $path Absolute path to the file/folder we try to (un)lock |
||
1939 | * @return bool |
||
1940 | */ |
||
1941 | 936 | protected function shouldLockFile($path) { |
|
1952 | |||
1953 | /** |
||
1954 | * Shortens the given absolute path to be relative to |
||
1955 | * "$user/files". |
||
1956 | * |
||
1957 | * @param string $absolutePath absolute path which is under "files" |
||
1958 | * |
||
1959 | * @return string path relative to "files" with trimmed slashes or null |
||
1960 | * if the path was NOT relative to files |
||
1961 | * |
||
1962 | * @throws \InvalidArgumentException if the given path was not under "files" |
||
1963 | * @since 8.1.0 |
||
1964 | */ |
||
1965 | 45 | public function getPathRelativeToFiles($absolutePath) { |
|
1977 | } |
||
1978 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: