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 |
||
85 | class View { |
||
86 | use EventEmitterTrait; |
||
87 | /** @var string */ |
||
88 | private $fakeRoot = ''; |
||
89 | |||
90 | /** |
||
91 | * @var \OCP\Lock\ILockingProvider |
||
92 | */ |
||
93 | private $lockingProvider; |
||
94 | |||
95 | /** @var bool */ |
||
96 | private $lockingEnabled; |
||
97 | |||
98 | /** @var bool */ |
||
99 | private $updaterEnabled = true; |
||
100 | |||
101 | /** @var \OC\User\Manager */ |
||
102 | private $userManager; |
||
103 | |||
104 | /** @var \OCP\ILogger */ |
||
105 | private $logger; |
||
106 | |||
107 | private $eventDispatcher; |
||
108 | |||
109 | /** |
||
110 | * @param string $root |
||
111 | * @throws \Exception If $root contains an invalid path |
||
112 | */ |
||
113 | public function __construct($root = '') { |
||
114 | if ($root === null) { |
||
115 | throw new \InvalidArgumentException('Root can\'t be null'); |
||
116 | } |
||
117 | if (!Filesystem::isValidPath($root)) { |
||
118 | throw new \Exception(); |
||
119 | } |
||
120 | |||
121 | $this->fakeRoot = $root; |
||
122 | $this->lockingProvider = \OC::$server->getLockingProvider(); |
||
123 | $this->lockingEnabled = !($this->lockingProvider instanceof \OC\Lock\NoopLockingProvider); |
||
124 | $this->userManager = \OC::$server->getUserManager(); |
||
125 | $this->logger = \OC::$server->getLogger(); |
||
126 | $this->eventDispatcher = \OC::$server->getEventDispatcher(); |
||
127 | } |
||
128 | |||
129 | public function getAbsolutePath($path = '/') { |
||
130 | if ($path === null) { |
||
131 | return null; |
||
132 | } |
||
133 | $this->assertPathLength($path); |
||
134 | if ($path === '') { |
||
135 | $path = '/'; |
||
136 | } |
||
137 | if ($path[0] !== '/') { |
||
138 | $path = '/' . $path; |
||
139 | } |
||
140 | return $this->fakeRoot . $path; |
||
141 | } |
||
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) { |
||
150 | if (!$fakeRoot == '') { |
||
151 | if ($fakeRoot[0] !== '/') { |
||
152 | $fakeRoot = '/' . $fakeRoot; |
||
153 | } |
||
154 | } |
||
155 | $this->fakeRoot = $fakeRoot; |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * get the fake root |
||
160 | * |
||
161 | * @return string |
||
162 | */ |
||
163 | public function getRoot() { |
||
164 | return $this->fakeRoot; |
||
165 | } |
||
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) { |
||
174 | $this->assertPathLength($path); |
||
175 | if ($this->fakeRoot == '') { |
||
176 | return $path; |
||
177 | } |
||
178 | |||
179 | if (\rtrim($path, '/') === \rtrim($this->fakeRoot, '/')) { |
||
180 | return '/'; |
||
181 | } |
||
182 | |||
183 | // missing slashes can cause wrong matches! |
||
184 | $root = \rtrim($this->fakeRoot, '/') . '/'; |
||
185 | |||
186 | if (\strpos($path, $root) !== 0) { |
||
187 | return null; |
||
188 | } else { |
||
189 | $path = \substr($path, \strlen($this->fakeRoot)); |
||
190 | if (\strlen($path) === 0) { |
||
191 | return '/'; |
||
192 | } else { |
||
193 | return $path; |
||
194 | } |
||
195 | } |
||
196 | } |
||
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) { |
||
208 | return Filesystem::getMountPoint($this->getAbsolutePath($path)); |
||
209 | } |
||
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) { |
||
221 | return Filesystem::getMountManager()->find($this->getAbsolutePath($path)); |
||
222 | } |
||
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) { |
||
231 | $a = $this->getAbsolutePath($path); |
||
232 | $p = Filesystem::normalizePath($a); |
||
233 | return Filesystem::resolvePath($p); |
||
234 | } |
||
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) { |
|
245 | $parent = \substr($path, 0, \strrpos($path, '/')); |
||
246 | $path = $this->getAbsolutePath($path); |
||
247 | list($storage, $internalPath) = Filesystem::resolvePath($path); |
||
248 | if (Filesystem::isValidPath($parent) and $storage) { |
||
249 | return $storage->getLocalFile($internalPath); |
||
250 | } else { |
||
251 | return null; |
||
252 | } |
||
253 | } |
||
254 | |||
255 | /** |
||
256 | * @param string $path |
||
257 | * @return string |
||
258 | */ |
||
259 | View Code Duplication | public function getLocalFolder($path) { |
|
260 | $parent = \substr($path, 0, \strrpos($path, '/')); |
||
261 | $path = $this->getAbsolutePath($path); |
||
262 | list($storage, $internalPath) = Filesystem::resolvePath($path); |
||
263 | if (Filesystem::isValidPath($parent) and $storage) { |
||
264 | return $storage->getLocalFolder($internalPath); |
||
265 | } else { |
||
266 | return null; |
||
267 | } |
||
268 | } |
||
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) { |
||
276 | return $this->emittingCall(function () use (&$path) { |
||
277 | $result = $this->basicOperation('mkdir', $path, ['create', 'write']); |
||
278 | return $result; |
||
279 | }, ['before' => ['path' => $this->getAbsolutePath($path)], 'after' => ['path' => $this->getAbsolutePath($path)]], 'file', 'create'); |
||
280 | } |
||
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) { |
||
290 | if ($mount instanceof MoveableMount) { |
||
291 | // cut of /user/files to get the relative path to data/user/files |
||
292 | $pathParts = \explode('/', $path, 4); |
||
293 | $relPath = '/' . $pathParts[3]; |
||
294 | $this->lockFile($relPath, ILockingProvider::LOCK_SHARED, true); |
||
295 | \OC_Hook::emit( |
||
296 | Filesystem::CLASSNAME, "umount", |
||
297 | [Filesystem::signal_param_path => $relPath] |
||
298 | ); |
||
299 | $this->changeLock($relPath, ILockingProvider::LOCK_EXCLUSIVE, true); |
||
300 | $result = $mount->removeMount(); |
||
301 | $this->changeLock($relPath, ILockingProvider::LOCK_SHARED, true); |
||
302 | if ($result) { |
||
303 | \OC_Hook::emit( |
||
304 | Filesystem::CLASSNAME, "post_umount", |
||
305 | [Filesystem::signal_param_path => $relPath] |
||
306 | ); |
||
307 | } |
||
308 | $this->unlockFile($relPath, ILockingProvider::LOCK_SHARED, true); |
||
309 | return $result; |
||
310 | } else { |
||
311 | // do not allow deleting the storage's root / the mount point |
||
312 | // because for some storages it might delete the whole contents |
||
313 | // but isn't supposed to work that way |
||
314 | return false; |
||
315 | } |
||
316 | } |
||
317 | |||
318 | public function disableCacheUpdate() { |
||
319 | $this->updaterEnabled = false; |
||
320 | } |
||
321 | |||
322 | public function enableCacheUpdate() { |
||
323 | $this->updaterEnabled = true; |
||
324 | } |
||
325 | |||
326 | protected function writeUpdate(Storage $storage, $internalPath, $time = null) { |
||
327 | if ($this->updaterEnabled) { |
||
328 | if ($time === null) { |
||
329 | $time = \time(); |
||
330 | } |
||
331 | $storage->getUpdater()->update($internalPath, $time); |
||
332 | } |
||
333 | } |
||
334 | |||
335 | protected function removeUpdate(Storage $storage, $internalPath) { |
||
336 | if ($this->updaterEnabled) { |
||
337 | $storage->getUpdater()->remove($internalPath); |
||
338 | } |
||
339 | } |
||
340 | |||
341 | protected function renameUpdate(Storage $sourceStorage, Storage $targetStorage, $sourceInternalPath, $targetInternalPath) { |
||
342 | if ($this->updaterEnabled) { |
||
343 | $targetStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); |
||
344 | } |
||
345 | } |
||
346 | |||
347 | /** |
||
348 | * @param string $path |
||
349 | * @return bool|mixed |
||
350 | */ |
||
351 | public function rmdir($path) { |
||
352 | return $this->emittingCall(function () use (&$path) { |
||
353 | $absolutePath = $this->getAbsolutePath($path); |
||
354 | $mount = Filesystem::getMountManager()->find($absolutePath); |
||
355 | if ($mount->getInternalPath($absolutePath) === '') { |
||
356 | return $this->removeMount($mount, $absolutePath); |
||
|
|||
357 | } |
||
358 | if ($this->is_dir($path)) { |
||
359 | $result = $this->basicOperation('rmdir', $path, ['delete']); |
||
360 | } else { |
||
361 | $result = false; |
||
362 | } |
||
363 | |||
364 | View Code Duplication | if (!$result && !$this->file_exists($path)) { //clear ghost files from the cache on delete |
|
365 | $storage = $mount->getStorage(); |
||
366 | $internalPath = $mount->getInternalPath($absolutePath); |
||
367 | $storage->getUpdater()->remove($internalPath); |
||
368 | } |
||
369 | |||
370 | return $result; |
||
371 | }, ['before' => ['path' => $this->getAbsolutePath($path)], 'after' => ['path' => $this->getAbsolutePath($path)]], 'file', 'delete'); |
||
372 | } |
||
373 | |||
374 | /** |
||
375 | * @param string $path |
||
376 | * @return resource |
||
377 | */ |
||
378 | public function opendir($path) { |
||
379 | return $this->basicOperation('opendir', $path, ['read']); |
||
380 | } |
||
381 | |||
382 | /** |
||
383 | * @param string $path |
||
384 | * @return bool|mixed |
||
385 | */ |
||
386 | public function is_dir($path) { |
||
387 | if ($path == '/') { |
||
388 | return true; |
||
389 | } |
||
390 | return $this->basicOperation('is_dir', $path); |
||
391 | } |
||
392 | |||
393 | /** |
||
394 | * @param string $path |
||
395 | * @return bool|mixed |
||
396 | */ |
||
397 | public function is_file($path) { |
||
398 | if ($path == '/') { |
||
399 | return false; |
||
400 | } |
||
401 | return $this->basicOperation('is_file', $path); |
||
402 | } |
||
403 | |||
404 | /** |
||
405 | * @param string $path |
||
406 | * @return mixed |
||
407 | */ |
||
408 | public function stat($path) { |
||
409 | return $this->basicOperation('stat', $path); |
||
410 | } |
||
411 | |||
412 | /** |
||
413 | * @param string $path |
||
414 | * @return mixed |
||
415 | */ |
||
416 | public function filetype($path) { |
||
417 | return $this->basicOperation('filetype', $path); |
||
418 | } |
||
419 | |||
420 | /** |
||
421 | * @param string $path |
||
422 | * @return mixed |
||
423 | */ |
||
424 | public function filesize($path) { |
||
425 | return $this->basicOperation('filesize', $path); |
||
426 | } |
||
427 | |||
428 | /** |
||
429 | * @param string $path |
||
430 | * @return bool|mixed |
||
431 | * @throws \OCP\Files\InvalidPathException |
||
432 | */ |
||
433 | public function readFileToOutput($path) { |
||
434 | $this->assertPathLength($path); |
||
435 | @\ob_end_clean(); |
||
436 | $handle = $this->readFile($path)->detach(); |
||
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->readFile($path)->detach(); |
||
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 | return \ftell($handle) - $from; |
||
474 | } |
||
475 | |||
476 | throw new \OCP\Files\UnseekableException('fseek error'); |
||
477 | } |
||
478 | return false; |
||
479 | } |
||
480 | |||
481 | /** |
||
482 | * @param string $path |
||
483 | * @return mixed |
||
484 | */ |
||
485 | public function isCreatable($path) { |
||
488 | |||
489 | /** |
||
490 | * @param string $path |
||
491 | * @return mixed |
||
492 | */ |
||
493 | public function isReadable($path) { |
||
496 | |||
497 | /** |
||
498 | * @param string $path |
||
499 | * @return mixed |
||
500 | */ |
||
501 | public function isUpdatable($path) { |
||
504 | |||
505 | /** |
||
506 | * @param string $path |
||
507 | * @return bool|mixed |
||
508 | */ |
||
509 | public function isDeletable($path) { |
||
517 | |||
518 | /** |
||
519 | * @param string $path |
||
520 | * @return mixed |
||
521 | */ |
||
522 | public function isSharable($path) { |
||
525 | |||
526 | /** |
||
527 | * @param string $path |
||
528 | * @return bool|mixed |
||
529 | */ |
||
530 | public function file_exists($path) { |
||
536 | |||
537 | /** |
||
538 | * @param string $path |
||
539 | * @return mixed |
||
540 | */ |
||
541 | public function filemtime($path) { |
||
544 | |||
545 | /** |
||
546 | * @param string $path |
||
547 | * @param int|string $mtime |
||
548 | * @return bool |
||
549 | */ |
||
550 | public function touch($path, $mtime = null) { |
||
576 | |||
577 | /** |
||
578 | * @param string $path |
||
579 | * @return mixed |
||
580 | */ |
||
581 | public function file_get_contents($path) { |
||
586 | |||
587 | public function readFile(string $path, array $options = []): StreamInterface { |
||
588 | return $this->emittingCall(function () use ($path, $options) { |
||
589 | return $this->basicOperation('readFile', $path, ['read'], $options); |
||
590 | }, ['before' => ['path' => $this->getAbsolutePath($path)], 'after' => ['path' => $this->getAbsolutePath($path)]], 'file', 'read'); |
||
591 | } |
||
592 | |||
593 | /** |
||
594 | * @param bool $exists |
||
595 | * @param string $path |
||
596 | * @param bool $run |
||
597 | */ |
||
598 | protected function emit_file_hooks_pre($exists, $path, &$run) { |
||
599 | $event = new GenericEvent(null); |
||
600 | if (!$exists) { |
||
601 | \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_create, [ |
||
602 | Filesystem::signal_param_path => $this->getHookPath($path), |
||
603 | Filesystem::signal_param_run => &$run, |
||
604 | ]); |
||
605 | View Code Duplication | if ($run) { |
|
606 | $event->setArgument('run', $run); |
||
607 | $this->eventDispatcher->dispatch('file.beforeCreate', $event); |
||
608 | if ($event->getArgument('run') === false) { |
||
609 | $run = $event->getArgument('run'); |
||
610 | } |
||
611 | } |
||
612 | } else { |
||
613 | \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_update, [ |
||
638 | |||
639 | /** |
||
640 | * @param bool $exists |
||
641 | * @param string $path |
||
642 | */ |
||
643 | protected function emit_file_hooks_post($exists, $path) { |
||
660 | |||
661 | /** |
||
662 | * @param string $path |
||
663 | * @param mixed $data |
||
664 | * @return bool|mixed |
||
665 | * @throws \Exception |
||
666 | */ |
||
667 | public function file_put_contents($path, $data) { |
||
718 | |||
719 | /** |
||
720 | * @param string $path |
||
721 | * @param StreamInterface $stream |
||
722 | * @return int |
||
723 | * @throws \Exception |
||
724 | */ |
||
725 | public function writeFile(string $path, StreamInterface $stream): int { |
||
728 | |||
729 | /** |
||
730 | * @param string $path |
||
731 | * @return bool|mixed |
||
732 | */ |
||
733 | public function unlink($path) { |
||
761 | |||
762 | /** |
||
763 | * @param string $directory |
||
764 | * @return bool|mixed |
||
765 | */ |
||
766 | public function deleteAll($directory) { |
||
769 | |||
770 | /** |
||
771 | * Rename/move a file or folder from the source path to target path. |
||
772 | * |
||
773 | * @param string $path1 source path |
||
774 | * @param string $path2 target path |
||
775 | * |
||
776 | * @return bool|mixed |
||
777 | */ |
||
778 | public function rename($path1, $path2) { |
||
897 | |||
898 | /** |
||
899 | * Copy a file/folder from the source path to target path |
||
900 | * |
||
901 | * @param string $path1 source path |
||
902 | * @param string $path2 target path |
||
903 | * @param bool $preserveMtime whether to preserve mtime on the copy |
||
904 | * |
||
905 | * @return bool|mixed |
||
906 | */ |
||
907 | |||
908 | public function copy($path1, $path2, $preserveMtime = false) { |
||
1004 | |||
1005 | /** |
||
1006 | * @param string $path |
||
1007 | * @param string $mode |
||
1008 | * @return resource |
||
1009 | * @deprecated 11.0.0 |
||
1010 | */ |
||
1011 | public function fopen($path, $mode) { |
||
1014 | |||
1015 | /** |
||
1016 | * @param string $path |
||
1017 | * @return bool|string |
||
1018 | * @throws \OCP\Files\InvalidPathException |
||
1019 | */ |
||
1020 | public function toTmpFile($path) { |
||
1036 | |||
1037 | /** |
||
1038 | * @param string $tmpFile |
||
1039 | * @param string $path |
||
1040 | * @return bool|mixed |
||
1041 | * @throws \OCP\Files\InvalidPathException |
||
1042 | */ |
||
1043 | public function fromTmpFile($tmpFile, $path) { |
||
1076 | |||
1077 | /** |
||
1078 | * @param string $path |
||
1079 | * @return mixed |
||
1080 | * @throws \OCP\Files\InvalidPathException |
||
1081 | */ |
||
1082 | public function getMimeType($path) { |
||
1086 | |||
1087 | /** |
||
1088 | * @param string $type |
||
1089 | * @param string $path |
||
1090 | * @param bool $raw |
||
1091 | * @return bool|null|string |
||
1092 | */ |
||
1093 | public function hash($type, $path, $raw = false) { |
||
1117 | |||
1118 | /** |
||
1119 | * @param string $path |
||
1120 | * @return mixed |
||
1121 | * @throws \OCP\Files\InvalidPathException |
||
1122 | */ |
||
1123 | public function free_space($path = '/') { |
||
1127 | |||
1128 | /** |
||
1129 | * abstraction layer for basic filesystem functions: wrapper for \OC\Files\Storage\Storage |
||
1130 | * |
||
1131 | * @param string $operation |
||
1132 | * @param string $path |
||
1133 | * @param array $hooks (optional) |
||
1134 | * @param mixed $extraParam (optional) |
||
1135 | * @return mixed |
||
1136 | * @throws \Exception |
||
1137 | * |
||
1138 | * This method takes requests for basic filesystem functions (e.g. reading & writing |
||
1139 | * files), processes hooks and proxies, sanitises paths, and finally passes them on to |
||
1140 | * \OC\Files\Storage\Storage for delegation to a storage backend for execution |
||
1141 | */ |
||
1142 | private function basicOperation($operation, $path, $hooks = [], $extraParam = null) { |
||
1226 | |||
1227 | /** |
||
1228 | * get the path relative to the default root for hook usage |
||
1229 | * |
||
1230 | * @param string $path |
||
1231 | * @return string |
||
1232 | */ |
||
1233 | private function getHookPath($path) { |
||
1239 | |||
1240 | private function shouldEmitHooks($path = '') { |
||
1262 | |||
1263 | /** |
||
1264 | * @param string[] $hooks |
||
1265 | * @param string $path |
||
1266 | * @param bool $post |
||
1267 | * @return bool |
||
1268 | */ |
||
1269 | private function runHooks($hooks, $path, $post = false) { |
||
1301 | |||
1302 | /** |
||
1303 | * check if a file or folder has been updated since $time |
||
1304 | * |
||
1305 | * @param string $path |
||
1306 | * @param int $time |
||
1307 | * @return bool |
||
1308 | */ |
||
1309 | public function hasUpdated($path, $time) { |
||
1312 | |||
1313 | /** |
||
1314 | * @param string $ownerId |
||
1315 | * @return IUser |
||
1316 | */ |
||
1317 | private function getUserObjectForOwner($ownerId) { |
||
1325 | |||
1326 | /** |
||
1327 | * Get file info from cache |
||
1328 | * |
||
1329 | * If the file is not in cached it will be scanned |
||
1330 | * If the file has changed on storage the cache will be updated |
||
1331 | * |
||
1332 | * @param \OC\Files\Storage\Storage $storage |
||
1333 | * @param string $internalPath |
||
1334 | * @param string $relativePath |
||
1335 | * @return array|bool |
||
1336 | */ |
||
1337 | private function getCacheEntry($storage, $internalPath, $relativePath) { |
||
1367 | |||
1368 | /** |
||
1369 | * get the filesystem info |
||
1370 | * |
||
1371 | * @param string $path |
||
1372 | * @param boolean|string $includeMountPoints true to add mountpoint sizes, |
||
1373 | * 'ext' to add only ext storage mount point sizes. Defaults to true. |
||
1374 | * defaults to true |
||
1375 | * @return \OC\Files\FileInfo|false False if file does not exist |
||
1376 | */ |
||
1377 | public function getFileInfo($path, $includeMountPoints = true) { |
||
1430 | |||
1431 | /** |
||
1432 | * get the content of a directory |
||
1433 | * |
||
1434 | * @param string $directory path under datadirectory |
||
1435 | * @param string $mimetype_filter limit returned content to this mimetype or mimepart |
||
1436 | * @return FileInfo[] |
||
1437 | */ |
||
1438 | public function getDirectoryContent($directory, $mimetype_filter = '') { |
||
1565 | |||
1566 | /** |
||
1567 | * change file metadata |
||
1568 | * |
||
1569 | * @param string $path |
||
1570 | * @param array|\OCP\Files\FileInfo $data |
||
1571 | * @return int |
||
1572 | * |
||
1573 | * returns the fileid of the updated file |
||
1574 | */ |
||
1575 | public function putFileInfo($path, $data) { |
||
1599 | |||
1600 | /** |
||
1601 | * search for files with the name matching $query |
||
1602 | * |
||
1603 | * @param string $query |
||
1604 | * @return FileInfo[] |
||
1605 | */ |
||
1606 | public function search($query) { |
||
1609 | |||
1610 | /** |
||
1611 | * search for files with the name matching $query |
||
1612 | * |
||
1613 | * @param string $query |
||
1614 | * @return FileInfo[] |
||
1615 | */ |
||
1616 | public function searchRaw($query) { |
||
1619 | |||
1620 | /** |
||
1621 | * search for files by mimetype |
||
1622 | * |
||
1623 | * @param string $mimetype |
||
1624 | * @return FileInfo[] |
||
1625 | */ |
||
1626 | public function searchByMime($mimetype) { |
||
1629 | |||
1630 | /** |
||
1631 | * search for files by tag |
||
1632 | * |
||
1633 | * @param string|int $tag name or tag id |
||
1634 | * @param string $userId owner of the tags |
||
1635 | * @return FileInfo[] |
||
1636 | */ |
||
1637 | public function searchByTag($tag, $userId) { |
||
1640 | |||
1641 | /** |
||
1642 | * @param string $method cache method |
||
1643 | * @param array $args |
||
1644 | * @return FileInfo[] |
||
1645 | */ |
||
1646 | private function searchCommon($method, $args) { |
||
1690 | |||
1691 | /** |
||
1692 | * Get the owner for a file or folder |
||
1693 | * |
||
1694 | * @param string $path |
||
1695 | * @return string the user id of the owner |
||
1696 | * @throws NotFoundException |
||
1697 | */ |
||
1698 | public function getOwner($path) { |
||
1705 | |||
1706 | /** |
||
1707 | * get the ETag for a file or folder |
||
1708 | * |
||
1709 | * @param string $path |
||
1710 | * @return string |
||
1711 | */ |
||
1712 | public function getETag($path) { |
||
1724 | |||
1725 | /** |
||
1726 | * Get the path of a file by id, relative to the view |
||
1727 | * |
||
1728 | * Note that the resulting path is not guarantied to be unique for the id, multiple paths can point to the same file |
||
1729 | * |
||
1730 | * @param int $id |
||
1731 | * @param bool $includeShares whether to recurse into shared mounts |
||
1732 | * @throws NotFoundException |
||
1733 | * @return string |
||
1734 | */ |
||
1735 | public function getPath($id, $includeShares = true) { |
||
1765 | |||
1766 | /** |
||
1767 | * @param string $path |
||
1768 | * @throws InvalidPathException |
||
1769 | */ |
||
1770 | private function assertPathLength($path) { |
||
1779 | |||
1780 | /** |
||
1781 | * check if it is allowed to move a mount point to a given target. |
||
1782 | * It is not allowed to move a mount point into a different mount point or |
||
1783 | * into an already shared folder |
||
1784 | * |
||
1785 | * @param MoveableMount $mount1 moveable mount |
||
1786 | * @param string $target absolute target path |
||
1787 | * @return boolean |
||
1788 | */ |
||
1789 | private function canMove(MoveableMount $mount1, $target) { |
||
1800 | |||
1801 | /** |
||
1802 | * Get a fileinfo object for files that are ignored in the cache (part files) |
||
1803 | * |
||
1804 | * @param string $path |
||
1805 | * @return \OCP\Files\FileInfo |
||
1806 | */ |
||
1807 | private function getPartFileInfo($path) { |
||
1830 | |||
1831 | /** |
||
1832 | * @param string $path |
||
1833 | * @param string $fileName |
||
1834 | * @throws InvalidPathException |
||
1835 | */ |
||
1836 | public function verifyPath($path, $fileName) { |
||
1879 | |||
1880 | /** |
||
1881 | * get all parent folders of $path |
||
1882 | * |
||
1883 | * @param string $path |
||
1884 | * @return string[] |
||
1885 | */ |
||
1886 | private function getParents($path) { |
||
1906 | |||
1907 | /** |
||
1908 | * Returns the mount point for which to lock |
||
1909 | * |
||
1910 | * @param string $absolutePath absolute path |
||
1911 | * @param bool $useParentMount true to return parent mount instead of whatever |
||
1912 | * is mounted directly on the given path, false otherwise |
||
1913 | * @return \OC\Files\Mount\MountPoint mount point for which to apply locks |
||
1914 | */ |
||
1915 | private function getMountForLock($absolutePath, $useParentMount = false) { |
||
1933 | |||
1934 | /** |
||
1935 | * Lock the given path |
||
1936 | * |
||
1937 | * @param string $path the path of the file to lock, relative to the view |
||
1938 | * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
||
1939 | * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage |
||
1940 | * |
||
1941 | * @return bool False if the path is excluded from locking, true otherwise |
||
1942 | * @throws \OCP\Lock\LockedException if the path is already locked |
||
1943 | */ |
||
1944 | View Code Duplication | private function lockPath($path, $type, $lockMountPoint = false) { |
|
1973 | |||
1974 | /** |
||
1975 | * Change the lock type |
||
1976 | * |
||
1977 | * @param string $path the path of the file to lock, relative to the view |
||
1978 | * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
||
1979 | * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage |
||
1980 | * |
||
1981 | * @return bool False if the path is excluded from locking, true otherwise |
||
1982 | * @throws \OCP\Lock\LockedException if the path is already locked |
||
1983 | */ |
||
1984 | View Code Duplication | public function changeLock($path, $type, $lockMountPoint = false) { |
|
2014 | |||
2015 | /** |
||
2016 | * Unlock the given path |
||
2017 | * |
||
2018 | * @param string $path the path of the file to unlock, relative to the view |
||
2019 | * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
||
2020 | * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage |
||
2021 | * |
||
2022 | * @return bool False if the path is excluded from locking, true otherwise |
||
2023 | */ |
||
2024 | private function unlockPath($path, $type, $lockMountPoint = false) { |
||
2045 | |||
2046 | /** |
||
2047 | * Lock a path and all its parents up to the root of the view |
||
2048 | * |
||
2049 | * @param string $path the path of the file to lock relative to the view |
||
2050 | * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
||
2051 | * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage |
||
2052 | * |
||
2053 | * @return bool False if the path is excluded from locking, true otherwise |
||
2054 | */ |
||
2055 | View Code Duplication | public function lockFile($path, $type, $lockMountPoint = false) { |
|
2071 | |||
2072 | /** |
||
2073 | * Unlock a path and all its parents up to the root of the view |
||
2074 | * |
||
2075 | * @param string $path the path of the file to lock relative to the view |
||
2076 | * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
||
2077 | * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage |
||
2078 | * |
||
2079 | * @return bool False if the path is excluded from locking, true otherwise |
||
2080 | */ |
||
2081 | View Code Duplication | public function unlockFile($path, $type, $lockMountPoint = false) { |
|
2097 | |||
2098 | /** |
||
2099 | * Only lock files in data/user/files/ |
||
2100 | * |
||
2101 | * @param string $path Absolute path to the file/folder we try to (un)lock |
||
2102 | * @return bool |
||
2103 | */ |
||
2104 | protected function shouldLockFile($path) { |
||
2115 | |||
2116 | /** |
||
2117 | * Shortens the given absolute path to be relative to |
||
2118 | * "$user/files". |
||
2119 | * |
||
2120 | * @param string $absolutePath absolute path which is under "files" |
||
2121 | * |
||
2122 | * @return string path relative to "files" with trimmed slashes or null |
||
2123 | * if the path was NOT relative to files |
||
2124 | * |
||
2125 | * @throws \InvalidArgumentException if the given path was not under "files" |
||
2126 | * @since 8.1.0 |
||
2127 | */ |
||
2128 | public function getPathRelativeToFiles($absolutePath) { |
||
2140 | |||
2141 | /** |
||
2142 | * @param string $filename |
||
2143 | * @return array |
||
2144 | * @throws \OC\User\NoUserException |
||
2145 | * @throws NotFoundException |
||
2146 | */ |
||
2147 | public function getUidAndFilename($filename) { |
||
2164 | |||
2165 | /** |
||
2166 | * Creates parent non-existing folders |
||
2167 | * |
||
2168 | * @param string $filePath |
||
2169 | * @return bool |
||
2170 | */ |
||
2171 | private function createParentDirectories($filePath) { |
||
2182 | } |
||
2183 |
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: