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 |
||
83 | class View { |
||
84 | use EventEmitterTrait; |
||
85 | /** @var string */ |
||
86 | private $fakeRoot = ''; |
||
87 | |||
88 | /** |
||
89 | * @var \OCP\Lock\ILockingProvider |
||
90 | */ |
||
91 | private $lockingProvider; |
||
92 | |||
93 | /** @var bool */ |
||
94 | private $lockingEnabled; |
||
95 | |||
96 | /** @var bool */ |
||
97 | private $updaterEnabled = true; |
||
98 | |||
99 | /** @var \OC\User\Manager */ |
||
100 | private $userManager; |
||
101 | |||
102 | /** @var \OCP\ILogger */ |
||
103 | private $logger; |
||
104 | |||
105 | private $eventDispatcher; |
||
106 | |||
107 | private static $ignorePartFile = false; |
||
108 | |||
109 | /** |
||
110 | * @param string $root |
||
111 | * @throws \Exception If $root contains an invalid path |
||
112 | */ |
||
113 | public function __construct($root = '') { |
||
128 | |||
129 | public function getAbsolutePath($path = '/') { |
||
142 | |||
143 | /** |
||
144 | * change the root to a fake root |
||
145 | * |
||
146 | * @param string $fakeRoot |
||
147 | * @return boolean|null |
||
148 | */ |
||
149 | public function chroot($fakeRoot) { |
||
157 | |||
158 | /** |
||
159 | * get the fake root |
||
160 | * |
||
161 | * @return string |
||
162 | */ |
||
163 | public function getRoot() { |
||
166 | |||
167 | /** |
||
168 | * get path relative to the root of the view |
||
169 | * |
||
170 | * @param string $path |
||
171 | * @return string |
||
172 | */ |
||
173 | public function getRelativePath($path) { |
||
197 | |||
198 | /** |
||
199 | * get the mountpoint of the storage object for a path |
||
200 | * ( note: because a storage is not always mounted inside the fakeroot, the |
||
201 | * returned mountpoint is relative to the absolute root of the filesystem |
||
202 | * and does not take the chroot into account ) |
||
203 | * |
||
204 | * @param string $path |
||
205 | * @return string |
||
206 | */ |
||
207 | public function getMountPoint($path) { |
||
210 | |||
211 | /** |
||
212 | * get the mountpoint of the storage object for a path |
||
213 | * ( note: because a storage is not always mounted inside the fakeroot, the |
||
214 | * returned mountpoint is relative to the absolute root of the filesystem |
||
215 | * and does not take the chroot into account ) |
||
216 | * |
||
217 | * @param string $path |
||
218 | * @return \OCP\Files\Mount\IMountPoint |
||
219 | */ |
||
220 | public function getMount($path) { |
||
223 | |||
224 | /** |
||
225 | * resolve a path to a storage and internal path |
||
226 | * |
||
227 | * @param string $path |
||
228 | * @return array an array consisting of the storage and the internal path |
||
229 | */ |
||
230 | public function resolvePath($path) { |
||
235 | |||
236 | /** |
||
237 | * return the path to a local version of the file |
||
238 | * we need this because we can't know if a file is stored local or not from |
||
239 | * outside the filestorage and for some purposes a local file is needed |
||
240 | * |
||
241 | * @param string $path |
||
242 | * @return string |
||
243 | */ |
||
244 | View Code Duplication | public function getLocalFile($path) { |
|
254 | |||
255 | /** |
||
256 | * @param string $path |
||
257 | * @return string |
||
258 | */ |
||
259 | View Code Duplication | public function getLocalFolder($path) { |
|
269 | |||
270 | /** |
||
271 | * the following functions operate with arguments and return values identical |
||
272 | * to those of their PHP built-in equivalents. Mostly they are merely wrappers |
||
273 | * for \OC\Files\Storage\Storage via basicOperation(). |
||
274 | */ |
||
275 | public function mkdir($path) { |
||
281 | |||
282 | /** |
||
283 | * remove mount point |
||
284 | * |
||
285 | * @param \OC\Files\Mount\MoveableMount $mount |
||
286 | * @param string $path relative to data/ |
||
287 | * @return boolean |
||
288 | */ |
||
289 | protected function removeMount($mount, $path) { |
||
317 | |||
318 | public function disableCacheUpdate() { |
||
321 | |||
322 | public function enableCacheUpdate() { |
||
325 | |||
326 | protected function writeUpdate(Storage $storage, $internalPath, $time = null) { |
||
334 | |||
335 | protected function removeUpdate(Storage $storage, $internalPath) { |
||
340 | |||
341 | protected function renameUpdate(Storage $sourceStorage, Storage $targetStorage, $sourceInternalPath, $targetInternalPath) { |
||
346 | |||
347 | /** |
||
348 | * @param string $path |
||
349 | * @return bool|mixed |
||
350 | */ |
||
351 | public function rmdir($path) { |
||
373 | |||
374 | /** |
||
375 | * @param string $path |
||
376 | * @return resource |
||
377 | */ |
||
378 | public function opendir($path) { |
||
381 | |||
382 | /** |
||
383 | * @param string $path |
||
384 | * @return bool|mixed |
||
385 | */ |
||
386 | public function is_dir($path) { |
||
392 | |||
393 | /** |
||
394 | * @param string $path |
||
395 | * @return bool|mixed |
||
396 | */ |
||
397 | public function is_file($path) { |
||
403 | |||
404 | /** |
||
405 | * @param string $path |
||
406 | * @return mixed |
||
407 | */ |
||
408 | public function stat($path) { |
||
411 | |||
412 | /** |
||
413 | * @param string $path |
||
414 | * @return mixed |
||
415 | */ |
||
416 | public function filetype($path) { |
||
419 | |||
420 | /** |
||
421 | * @param string $path |
||
422 | * @return mixed |
||
423 | */ |
||
424 | public function filesize($path) { |
||
427 | |||
428 | /** |
||
429 | * @param string $path |
||
430 | * @return bool|mixed |
||
431 | * @throws \OCP\Files\InvalidPathException |
||
432 | */ |
||
433 | public function readfile($path) { |
||
434 | $this->assertPathLength($path); |
||
435 | @\ob_end_clean(); |
||
436 | $handle = $this->fopen($path, 'rb'); |
||
437 | if ($handle) { |
||
438 | $chunkSize = 8192; // 8 kB chunks |
||
439 | while (!\feof($handle)) { |
||
440 | echo \fread($handle, $chunkSize); |
||
441 | \flush(); |
||
442 | } |
||
443 | $size = $this->filesize($path); |
||
444 | return $size; |
||
445 | } |
||
446 | return false; |
||
447 | } |
||
448 | |||
449 | /** |
||
450 | * @param string $path |
||
451 | * @param int $from |
||
452 | * @param int $to |
||
453 | * @return bool|mixed |
||
454 | * @throws \OCP\Files\InvalidPathException |
||
455 | * @throws \OCP\Files\UnseekableException |
||
456 | */ |
||
457 | public function readfilePart($path, $from, $to) { |
||
458 | $this->assertPathLength($path); |
||
459 | @\ob_end_clean(); |
||
460 | $handle = $this->fopen($path, 'rb'); |
||
461 | if ($handle) { |
||
462 | if (\fseek($handle, $from) === 0) { |
||
463 | $chunkSize = 8192; // 8 kB chunks |
||
464 | $end = $to + 1; |
||
465 | while (!\feof($handle) && \ftell($handle) < $end) { |
||
466 | $len = $end - \ftell($handle); |
||
467 | if ($len > $chunkSize) { |
||
468 | $len = $chunkSize; |
||
469 | } |
||
470 | echo \fread($handle, $len); |
||
471 | \flush(); |
||
472 | } |
||
473 | $size = \ftell($handle) - $from; |
||
474 | return $size; |
||
475 | } |
||
476 | |||
477 | throw new \OCP\Files\UnseekableException('fseek error'); |
||
478 | } |
||
479 | return false; |
||
480 | } |
||
481 | |||
482 | /** |
||
483 | * @param string $path |
||
484 | * @return mixed |
||
485 | */ |
||
486 | public function isCreatable($path) { |
||
487 | return $this->basicOperation('isCreatable', $path); |
||
488 | } |
||
489 | |||
490 | /** |
||
491 | * @param string $path |
||
492 | * @return mixed |
||
493 | */ |
||
494 | public function isReadable($path) { |
||
495 | return $this->basicOperation('isReadable', $path); |
||
496 | } |
||
497 | |||
498 | /** |
||
499 | * @param string $path |
||
500 | * @return mixed |
||
501 | */ |
||
502 | public function isUpdatable($path) { |
||
503 | return $this->basicOperation('isUpdatable', $path); |
||
504 | } |
||
505 | |||
506 | /** |
||
507 | * @param string $path |
||
508 | * @return bool|mixed |
||
509 | */ |
||
510 | public function isDeletable($path) { |
||
511 | $absolutePath = $this->getAbsolutePath($path); |
||
512 | $mount = Filesystem::getMountManager()->find($absolutePath); |
||
513 | if ($mount->getInternalPath($absolutePath) === '') { |
||
514 | return $mount instanceof MoveableMount; |
||
515 | } |
||
516 | return $this->basicOperation('isDeletable', $path); |
||
517 | } |
||
518 | |||
519 | /** |
||
520 | * @param string $path |
||
521 | * @return mixed |
||
522 | */ |
||
523 | public function isSharable($path) { |
||
524 | return $this->basicOperation('isSharable', $path); |
||
525 | } |
||
526 | |||
527 | /** |
||
528 | * @param string $path |
||
529 | * @return bool|mixed |
||
530 | */ |
||
531 | public function file_exists($path) { |
||
532 | if ($path == '/') { |
||
533 | return true; |
||
534 | } |
||
535 | return $this->basicOperation('file_exists', $path); |
||
536 | } |
||
537 | |||
538 | /** |
||
539 | * @param string $path |
||
540 | * @return mixed |
||
541 | */ |
||
542 | public function filemtime($path) { |
||
543 | return $this->basicOperation('filemtime', $path); |
||
544 | } |
||
545 | |||
546 | /** |
||
547 | * @param string $path |
||
548 | * @param int|string $mtime |
||
549 | * @return bool |
||
550 | */ |
||
551 | public function touch($path, $mtime = null) { |
||
552 | if ($mtime !== null and !\is_numeric($mtime)) { |
||
553 | $mtime = \strtotime($mtime); |
||
554 | } |
||
555 | |||
556 | $hooks = ['touch']; |
||
557 | |||
558 | if (!$this->file_exists($path)) { |
||
559 | $hooks[] = 'create'; |
||
560 | $hooks[] = 'write'; |
||
561 | } |
||
562 | $result = $this->basicOperation('touch', $path, $hooks, $mtime); |
||
563 | if (!$result) { |
||
564 | // If create file fails because of permissions on external storage like SMB folders, |
||
565 | // check file exists and return false if not. |
||
566 | if (!$this->file_exists($path)) { |
||
567 | return false; |
||
568 | } |
||
569 | if ($mtime === null) { |
||
570 | $mtime = \time(); |
||
571 | } |
||
572 | //if native touch fails, we emulate it by changing the mtime in the cache |
||
573 | $this->putFileInfo($path, ['mtime' => $mtime]); |
||
574 | } |
||
575 | return true; |
||
576 | } |
||
577 | |||
578 | /** |
||
579 | * @param string $path |
||
580 | * @return mixed |
||
581 | */ |
||
582 | public function file_get_contents($path) { |
||
583 | return $this->emittingCall(function () use (&$path) { |
||
584 | return $this->basicOperation('file_get_contents', $path, ['read']); |
||
585 | }, ['before' => ['path' => $this->getAbsolutePath($path)], 'after' => ['path' => $this->getAbsolutePath($path)]], 'file', 'read'); |
||
586 | } |
||
587 | |||
588 | /** |
||
589 | * @param bool $exists |
||
590 | * @param string $path |
||
591 | * @param bool $run |
||
592 | */ |
||
593 | protected function emit_file_hooks_pre($exists, $path, &$run) { |
||
594 | $event = new GenericEvent(null); |
||
595 | if (!$exists) { |
||
596 | \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_create, [ |
||
597 | Filesystem::signal_param_path => $this->getHookPath($path), |
||
598 | Filesystem::signal_param_run => &$run, |
||
599 | ]); |
||
600 | View Code Duplication | if ($run) { |
|
601 | $event->setArgument('run', $run); |
||
602 | $this->eventDispatcher->dispatch('file.beforeCreate', $event); |
||
603 | if ($event->getArgument('run') === false) { |
||
604 | $run = $event->getArgument('run'); |
||
605 | } |
||
606 | } |
||
607 | } else { |
||
608 | \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_update, [ |
||
609 | Filesystem::signal_param_path => $this->getHookPath($path), |
||
610 | Filesystem::signal_param_run => &$run, |
||
611 | ]); |
||
612 | View Code Duplication | if ($run) { |
|
613 | $event->setArgument('run', $run); |
||
614 | $this->eventDispatcher->dispatch('file.beforeUpdate', $event); |
||
615 | if ($event->getArgument('run') === false) { |
||
616 | $run = $event->getArgument('run'); |
||
617 | } |
||
618 | } |
||
619 | } |
||
620 | |||
621 | \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_write, [ |
||
622 | Filesystem::signal_param_path => $this->getHookPath($path), |
||
623 | Filesystem::signal_param_run => &$run, |
||
624 | ]); |
||
625 | View Code Duplication | if ($run) { |
|
626 | $event->setArgument('run', $run); |
||
627 | $this->eventDispatcher->dispatch('file.beforeWrite', $event); |
||
628 | if ($event->getArgument('run') === false) { |
||
629 | $run = $event->getArgument('run'); |
||
630 | } |
||
631 | } |
||
632 | } |
||
633 | |||
634 | /** |
||
635 | * @param bool $exists |
||
636 | * @param string $path |
||
637 | */ |
||
638 | protected function emit_file_hooks_post($exists, $path) { |
||
639 | // A post event so no before event args required |
||
640 | return $this->emittingCall(function () use (&$exists, &$path) { |
||
641 | View Code Duplication | if (!$exists) { |
|
642 | \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_post_create, [ |
||
643 | Filesystem::signal_param_path => $this->getHookPath($path), |
||
644 | ]); |
||
645 | } else { |
||
646 | \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_post_update, [ |
||
647 | Filesystem::signal_param_path => $this->getHookPath($path), |
||
648 | ]); |
||
649 | } |
||
650 | \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_post_write, [ |
||
651 | Filesystem::signal_param_path => $this->getHookPath($path), |
||
652 | ]); |
||
653 | }, ['before' => ['path' => $path], 'after' => ['path' => $this->getAbsolutePath($path)]], 'file', 'create'); |
||
654 | } |
||
655 | |||
656 | /** |
||
657 | * @param string $path |
||
658 | * @param mixed $data |
||
659 | * @return bool|mixed |
||
660 | * @throws \Exception |
||
661 | */ |
||
662 | public function file_put_contents($path, $data) { |
||
663 | return $this->emittingCall(function () use (&$path, &$data) { |
||
664 | if (\is_resource($data)) { //not having to deal with streams in file_put_contents makes life easier |
||
665 | $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); |
||
666 | if (Filesystem::isValidPath($path) |
||
667 | and !Filesystem::isForbiddenFileOrDir($path) |
||
668 | ) { |
||
669 | $path = $this->getRelativePath($absolutePath); |
||
670 | |||
671 | $this->lockFile($path, ILockingProvider::LOCK_SHARED); |
||
672 | |||
673 | $exists = $this->file_exists($path); |
||
674 | $run = true; |
||
675 | if ($this->shouldEmitHooks($path)) { |
||
676 | $this->emit_file_hooks_pre($exists, $path, $run); |
||
677 | } |
||
678 | if (!$run) { |
||
679 | $this->unlockFile($path, ILockingProvider::LOCK_SHARED); |
||
680 | return false; |
||
681 | } |
||
682 | |||
683 | $this->changeLock($path, ILockingProvider::LOCK_EXCLUSIVE); |
||
684 | |||
685 | /** @var \OC\Files\Storage\Storage $storage */ |
||
686 | list($storage, $internalPath) = $this->resolvePath($path); |
||
687 | $target = $storage->fopen($internalPath, 'w'); |
||
688 | if ($target) { |
||
689 | list(, $result) = \OC_Helper::streamCopy($data, $target); |
||
690 | \fclose($target); |
||
691 | \fclose($data); |
||
692 | |||
693 | $this->writeUpdate($storage, $internalPath); |
||
694 | |||
695 | $this->changeLock($path, ILockingProvider::LOCK_SHARED); |
||
696 | |||
697 | if ($this->shouldEmitHooks($path) && $result !== false) { |
||
698 | $this->emit_file_hooks_post($exists, $path); |
||
699 | } |
||
700 | $this->unlockFile($path, ILockingProvider::LOCK_SHARED); |
||
701 | return $result; |
||
702 | } else { |
||
703 | $this->unlockFile($path, ILockingProvider::LOCK_EXCLUSIVE); |
||
704 | return false; |
||
705 | } |
||
706 | } else { |
||
707 | return false; |
||
708 | } |
||
709 | } else { |
||
710 | $hooks = ($this->file_exists($path)) ? ['update', 'write'] : ['create', 'write']; |
||
711 | return $this->basicOperation('file_put_contents', $path, $hooks, $data); |
||
712 | } |
||
713 | }, ['before' => ['path' => $this->getAbsolutePath($path)], 'after' => ['path' => $this->getAbsolutePath($path)]], 'file', 'update'); |
||
714 | } |
||
715 | |||
716 | /** |
||
717 | * @param string $path |
||
718 | * @return bool|mixed |
||
719 | */ |
||
720 | public function unlink($path) { |
||
721 | return $this->emittingCall(function () use (&$path) { |
||
722 | if ($path === '' || $path === '/') { |
||
723 | // do not allow deleting the root |
||
724 | return false; |
||
725 | } |
||
726 | $postFix = (\substr($path, -1, 1) === '/') ? '/' : ''; |
||
727 | $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); |
||
728 | $mount = Filesystem::getMountManager()->find($absolutePath . $postFix); |
||
729 | if ($mount and $mount->getInternalPath($absolutePath) === '') { |
||
730 | return $this->removeMount($mount, $absolutePath); |
||
731 | } |
||
732 | if ($this->is_dir($path)) { |
||
733 | $result = $this->basicOperation('rmdir', $path, ['delete']); |
||
734 | } else { |
||
735 | $result = $this->basicOperation('unlink', $path, ['delete']); |
||
736 | } |
||
737 | |||
738 | View Code Duplication | if (!$result && !$this->file_exists($path)) { //clear ghost files from the cache on delete |
|
739 | $storage = $mount->getStorage(); |
||
740 | $internalPath = $mount->getInternalPath($absolutePath); |
||
741 | $storage->getUpdater()->remove($internalPath); |
||
742 | return true; |
||
743 | } else { |
||
744 | return $result; |
||
745 | } |
||
746 | }, ['before' => ['path' => $this->getAbsolutePath($path)], 'after' => ['path' => $this->getAbsolutePath($path)]], 'file', 'delete'); |
||
747 | } |
||
748 | |||
749 | /** |
||
750 | * @param string $directory |
||
751 | * @return bool|mixed |
||
752 | */ |
||
753 | public function deleteAll($directory) { |
||
756 | |||
757 | /** |
||
758 | * Rename/move a file or folder from the source path to target path. |
||
759 | * |
||
760 | * @param string $path1 source path |
||
761 | * @param string $path2 target path |
||
762 | * |
||
763 | * @return bool|mixed |
||
764 | */ |
||
765 | public function rename($path1, $path2) { |
||
766 | return $this->emittingCall(function () use (&$path1, &$path2) { |
||
767 | $absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1)); |
||
768 | $absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($path2)); |
||
769 | $result = false; |
||
770 | if ( |
||
771 | Filesystem::isValidPath($path2) |
||
884 | |||
885 | /** |
||
886 | * Copy a file/folder from the source path to target path |
||
887 | * |
||
888 | * @param string $path1 source path |
||
889 | * @param string $path2 target path |
||
890 | * @param bool $preserveMtime whether to preserve mtime on the copy |
||
891 | * |
||
892 | * @return bool|mixed |
||
893 | */ |
||
894 | |||
895 | public function copy($path1, $path2, $preserveMtime = false) { |
||
991 | |||
992 | /** |
||
993 | * @param string $path |
||
994 | * @param string $mode |
||
995 | * @return resource |
||
996 | */ |
||
997 | public function fopen($path, $mode) { |
||
1029 | |||
1030 | /** |
||
1031 | * @param string $path |
||
1032 | * @return bool|string |
||
1033 | * @throws \OCP\Files\InvalidPathException |
||
1034 | */ |
||
1035 | public function toTmpFile($path) { |
||
1051 | |||
1052 | /** |
||
1053 | * @param string $tmpFile |
||
1054 | * @param string $path |
||
1055 | * @return bool|mixed |
||
1056 | * @throws \OCP\Files\InvalidPathException |
||
1057 | */ |
||
1058 | public function fromTmpFile($tmpFile, $path) { |
||
1091 | |||
1092 | /** |
||
1093 | * @param string $path |
||
1094 | * @return mixed |
||
1095 | * @throws \OCP\Files\InvalidPathException |
||
1096 | */ |
||
1097 | public function getMimeType($path) { |
||
1101 | |||
1102 | /** |
||
1103 | * @param string $type |
||
1104 | * @param string $path |
||
1105 | * @param bool $raw |
||
1106 | * @return bool|null|string |
||
1107 | */ |
||
1108 | public function hash($type, $path, $raw = false) { |
||
1132 | |||
1133 | /** |
||
1134 | * @param string $path |
||
1135 | * @return mixed |
||
1136 | * @throws \OCP\Files\InvalidPathException |
||
1137 | */ |
||
1138 | public function free_space($path = '/') { |
||
1142 | |||
1143 | /** |
||
1144 | * abstraction layer for basic filesystem functions: wrapper for \OC\Files\Storage\Storage |
||
1145 | * |
||
1146 | * @param string $operation |
||
1147 | * @param string $path |
||
1148 | * @param array $hooks (optional) |
||
1149 | * @param mixed $extraParam (optional) |
||
1150 | * @return mixed |
||
1151 | * @throws \Exception |
||
1152 | * |
||
1153 | * This method takes requests for basic filesystem functions (e.g. reading & writing |
||
1154 | * files), processes hooks and proxies, sanitises paths, and finally passes them on to |
||
1155 | * \OC\Files\Storage\Storage for delegation to a storage backend for execution |
||
1156 | */ |
||
1157 | private function basicOperation($operation, $path, $hooks = [], $extraParam = null) { |
||
1241 | |||
1242 | /** |
||
1243 | * get the path relative to the default root for hook usage |
||
1244 | * |
||
1245 | * @param string $path |
||
1246 | * @return string |
||
1247 | */ |
||
1248 | private function getHookPath($path) { |
||
1254 | |||
1255 | private function shouldEmitHooks($path = '') { |
||
1277 | |||
1278 | /** |
||
1279 | * @param string[] $hooks |
||
1280 | * @param string $path |
||
1281 | * @param bool $post |
||
1282 | * @return bool |
||
1283 | */ |
||
1284 | private function runHooks($hooks, $path, $post = false) { |
||
1316 | |||
1317 | /** |
||
1318 | * check if a file or folder has been updated since $time |
||
1319 | * |
||
1320 | * @param string $path |
||
1321 | * @param int $time |
||
1322 | * @return bool |
||
1323 | */ |
||
1324 | public function hasUpdated($path, $time) { |
||
1327 | |||
1328 | /** |
||
1329 | * @param string $ownerId |
||
1330 | * @return IUser |
||
1331 | */ |
||
1332 | private function getUserObjectForOwner($ownerId) { |
||
1340 | |||
1341 | /** |
||
1342 | * Get file info from cache |
||
1343 | * |
||
1344 | * If the file is not in cached it will be scanned |
||
1345 | * If the file has changed on storage the cache will be updated |
||
1346 | * |
||
1347 | * @param \OC\Files\Storage\Storage $storage |
||
1348 | * @param string $internalPath |
||
1349 | * @param string $relativePath |
||
1350 | * @return array|bool |
||
1351 | */ |
||
1352 | private function getCacheEntry($storage, $internalPath, $relativePath) { |
||
1382 | |||
1383 | /** |
||
1384 | * get the filesystem info |
||
1385 | * |
||
1386 | * @param string $path |
||
1387 | * @param boolean|string $includeMountPoints true to add mountpoint sizes, |
||
1388 | * 'ext' to add only ext storage mount point sizes. Defaults to true. |
||
1389 | * defaults to true |
||
1390 | * @return \OC\Files\FileInfo|false False if file does not exist |
||
1391 | */ |
||
1392 | public function getFileInfo($path, $includeMountPoints = true) { |
||
1445 | |||
1446 | /** |
||
1447 | * get the content of a directory |
||
1448 | * |
||
1449 | * @param string $directory path under datadirectory |
||
1450 | * @param string $mimetype_filter limit returned content to this mimetype or mimepart |
||
1451 | * @return FileInfo[] |
||
1452 | */ |
||
1453 | public function getDirectoryContent($directory, $mimetype_filter = '') { |
||
1580 | |||
1581 | /** |
||
1582 | * change file metadata |
||
1583 | * |
||
1584 | * @param string $path |
||
1585 | * @param array|\OCP\Files\FileInfo $data |
||
1586 | * @return int |
||
1587 | * |
||
1588 | * returns the fileid of the updated file |
||
1589 | */ |
||
1590 | public function putFileInfo($path, $data) { |
||
1614 | |||
1615 | /** |
||
1616 | * search for files with the name matching $query |
||
1617 | * |
||
1618 | * @param string $query |
||
1619 | * @return FileInfo[] |
||
1620 | */ |
||
1621 | public function search($query) { |
||
1624 | |||
1625 | /** |
||
1626 | * search for files with the name matching $query |
||
1627 | * |
||
1628 | * @param string $query |
||
1629 | * @return FileInfo[] |
||
1630 | */ |
||
1631 | public function searchRaw($query) { |
||
1634 | |||
1635 | /** |
||
1636 | * search for files by mimetype |
||
1637 | * |
||
1638 | * @param string $mimetype |
||
1639 | * @return FileInfo[] |
||
1640 | */ |
||
1641 | public function searchByMime($mimetype) { |
||
1644 | |||
1645 | /** |
||
1646 | * search for files by tag |
||
1647 | * |
||
1648 | * @param string|int $tag name or tag id |
||
1649 | * @param string $userId owner of the tags |
||
1650 | * @return FileInfo[] |
||
1651 | */ |
||
1652 | public function searchByTag($tag, $userId) { |
||
1655 | |||
1656 | /** |
||
1657 | * @param string $method cache method |
||
1658 | * @param array $args |
||
1659 | * @return FileInfo[] |
||
1660 | */ |
||
1661 | private function searchCommon($method, $args) { |
||
1705 | |||
1706 | /** |
||
1707 | * Get the owner for a file or folder |
||
1708 | * |
||
1709 | * @param string $path |
||
1710 | * @return string the user id of the owner |
||
1711 | * @throws NotFoundException |
||
1712 | */ |
||
1713 | public function getOwner($path) { |
||
1720 | |||
1721 | /** |
||
1722 | * get the ETag for a file or folder |
||
1723 | * |
||
1724 | * @param string $path |
||
1725 | * @return string |
||
1726 | */ |
||
1727 | public function getETag($path) { |
||
1739 | |||
1740 | /** |
||
1741 | * Get the path of a file by id, relative to the view |
||
1742 | * |
||
1743 | * Note that the resulting path is not guarantied to be unique for the id, multiple paths can point to the same file |
||
1744 | * |
||
1745 | * @param int $id |
||
1746 | * @param bool $includeShares whether to recurse into shared mounts |
||
1747 | * @throws NotFoundException |
||
1748 | * @return string |
||
1749 | */ |
||
1750 | public function getPath($id, $includeShares = true) { |
||
1780 | |||
1781 | /** |
||
1782 | * @param string $path |
||
1783 | * @throws InvalidPathException |
||
1784 | */ |
||
1785 | private function assertPathLength($path) { |
||
1794 | |||
1795 | /** |
||
1796 | * check if it is allowed to move a mount point to a given target. |
||
1797 | * It is not allowed to move a mount point into a different mount point or |
||
1798 | * into an already shared folder |
||
1799 | * |
||
1800 | * @param MoveableMount $mount1 moveable mount |
||
1801 | * @param string $target absolute target path |
||
1802 | * @return boolean |
||
1803 | */ |
||
1804 | private function canMove(MoveableMount $mount1, $target) { |
||
1815 | |||
1816 | /** |
||
1817 | * Get a fileinfo object for files that are ignored in the cache (part files) |
||
1818 | * |
||
1819 | * @param string $path |
||
1820 | * @return \OCP\Files\FileInfo |
||
1821 | */ |
||
1822 | private function getPartFileInfo($path) { |
||
1845 | |||
1846 | /** |
||
1847 | * @param string $path |
||
1848 | * @param string $fileName |
||
1849 | * @throws InvalidPathException |
||
1850 | */ |
||
1851 | public function verifyPath($path, $fileName) { |
||
1894 | |||
1895 | /** |
||
1896 | * get all parent folders of $path |
||
1897 | * |
||
1898 | * @param string $path |
||
1899 | * @return string[] |
||
1900 | */ |
||
1901 | private function getParents($path) { |
||
1921 | |||
1922 | /** |
||
1923 | * Returns the mount point for which to lock |
||
1924 | * |
||
1925 | * @param string $absolutePath absolute path |
||
1926 | * @param bool $useParentMount true to return parent mount instead of whatever |
||
1927 | * is mounted directly on the given path, false otherwise |
||
1928 | * @return \OC\Files\Mount\MountPoint mount point for which to apply locks |
||
1929 | */ |
||
1930 | private function getMountForLock($absolutePath, $useParentMount = false) { |
||
1948 | |||
1949 | /** |
||
1950 | * Lock the given path |
||
1951 | * |
||
1952 | * @param string $path the path of the file to lock, relative to the view |
||
1953 | * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
||
1954 | * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage |
||
1955 | * |
||
1956 | * @return bool False if the path is excluded from locking, true otherwise |
||
1957 | * @throws \OCP\Lock\LockedException if the path is already locked |
||
1958 | */ |
||
1959 | View Code Duplication | private function lockPath($path, $type, $lockMountPoint = false) { |
|
1988 | |||
1989 | /** |
||
1990 | * Change the lock type |
||
1991 | * |
||
1992 | * @param string $path the path of the file to lock, relative to the view |
||
1993 | * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
||
1994 | * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage |
||
1995 | * |
||
1996 | * @return bool False if the path is excluded from locking, true otherwise |
||
1997 | * @throws \OCP\Lock\LockedException if the path is already locked |
||
1998 | */ |
||
1999 | View Code Duplication | public function changeLock($path, $type, $lockMountPoint = false) { |
|
2029 | |||
2030 | /** |
||
2031 | * Unlock the given path |
||
2032 | * |
||
2033 | * @param string $path the path of the file to unlock, relative to the view |
||
2034 | * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
||
2035 | * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage |
||
2036 | * |
||
2037 | * @return bool False if the path is excluded from locking, true otherwise |
||
2038 | */ |
||
2039 | private function unlockPath($path, $type, $lockMountPoint = false) { |
||
2060 | |||
2061 | /** |
||
2062 | * Lock a path and all its parents up to the root of the view |
||
2063 | * |
||
2064 | * @param string $path the path of the file to lock relative to the view |
||
2065 | * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
||
2066 | * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage |
||
2067 | * |
||
2068 | * @return bool False if the path is excluded from locking, true otherwise |
||
2069 | */ |
||
2070 | View Code Duplication | public function lockFile($path, $type, $lockMountPoint = false) { |
|
2086 | |||
2087 | /** |
||
2088 | * Unlock a path and all its parents up to the root of the view |
||
2089 | * |
||
2090 | * @param string $path the path of the file to lock relative to the view |
||
2091 | * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
||
2092 | * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage |
||
2093 | * |
||
2094 | * @return bool False if the path is excluded from locking, true otherwise |
||
2095 | */ |
||
2096 | View Code Duplication | public function unlockFile($path, $type, $lockMountPoint = false) { |
|
2112 | |||
2113 | /** |
||
2114 | * Only lock files in data/user/files/ |
||
2115 | * |
||
2116 | * @param string $path Absolute path to the file/folder we try to (un)lock |
||
2117 | * @return bool |
||
2118 | */ |
||
2119 | protected function shouldLockFile($path) { |
||
2130 | |||
2131 | /** |
||
2132 | * Shortens the given absolute path to be relative to |
||
2133 | * "$user/files". |
||
2134 | * |
||
2135 | * @param string $absolutePath absolute path which is under "files" |
||
2136 | * |
||
2137 | * @return string path relative to "files" with trimmed slashes or null |
||
2138 | * if the path was NOT relative to files |
||
2139 | * |
||
2140 | * @throws \InvalidArgumentException if the given path was not under "files" |
||
2141 | * @since 8.1.0 |
||
2142 | */ |
||
2143 | public function getPathRelativeToFiles($absolutePath) { |
||
2155 | |||
2156 | /** |
||
2157 | * @param string $filename |
||
2158 | * @return array |
||
2159 | * @throws \OC\User\NoUserException |
||
2160 | * @throws NotFoundException |
||
2161 | */ |
||
2162 | public function getUidAndFilename($filename) { |
||
2179 | |||
2180 | /** |
||
2181 | * Creates parent non-existing folders |
||
2182 | * |
||
2183 | * @param string $filePath |
||
2184 | * @return bool |
||
2185 | */ |
||
2186 | private function createParentDirectories($filePath) { |
||
2197 | |||
2198 | /** |
||
2199 | * User can create part files example to a call for rename(), in effect |
||
2200 | * it might not be a part file. So for better control in such cases this |
||
2201 | * method would help to let the method in rename() to know if it is a |
||
2202 | * part file. |
||
2203 | * |
||
2204 | * @param bool $isIgnored |
||
2205 | */ |
||
2206 | public static function setIgnorePartFile($isIgnored) { |
||
2209 | } |
||
2210 |
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: