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) { |
||
715 | |||
716 | public function writeFile(string $path, StreamInterface $stream): int { |
||
719 | |||
720 | /** |
||
721 | * @param string $path |
||
722 | * @return bool|mixed |
||
723 | */ |
||
724 | public function unlink($path) { |
||
752 | |||
753 | /** |
||
754 | * @param string $directory |
||
755 | * @return bool|mixed |
||
756 | */ |
||
757 | public function deleteAll($directory) { |
||
760 | |||
761 | /** |
||
762 | * Rename/move a file or folder from the source path to target path. |
||
763 | * |
||
764 | * @param string $path1 source path |
||
765 | * @param string $path2 target path |
||
766 | * |
||
767 | * @return bool|mixed |
||
768 | */ |
||
769 | public function rename($path1, $path2) { |
||
888 | |||
889 | /** |
||
890 | * Copy a file/folder from the source path to target path |
||
891 | * |
||
892 | * @param string $path1 source path |
||
893 | * @param string $path2 target path |
||
894 | * @param bool $preserveMtime whether to preserve mtime on the copy |
||
895 | * |
||
896 | * @return bool|mixed |
||
897 | */ |
||
898 | |||
899 | public function copy($path1, $path2, $preserveMtime = false) { |
||
995 | |||
996 | /** |
||
997 | * @param string $path |
||
998 | * @param string $mode |
||
999 | * @return resource |
||
1000 | * @deprecated 11.0.0 |
||
1001 | */ |
||
1002 | public function fopen($path, $mode) { |
||
1005 | |||
1006 | /** |
||
1007 | * @param string $path |
||
1008 | * @return bool|string |
||
1009 | * @throws \OCP\Files\InvalidPathException |
||
1010 | */ |
||
1011 | public function toTmpFile($path) { |
||
1027 | |||
1028 | /** |
||
1029 | * @param string $tmpFile |
||
1030 | * @param string $path |
||
1031 | * @return bool|mixed |
||
1032 | * @throws \OCP\Files\InvalidPathException |
||
1033 | */ |
||
1034 | public function fromTmpFile($tmpFile, $path) { |
||
1067 | |||
1068 | /** |
||
1069 | * @param string $path |
||
1070 | * @return mixed |
||
1071 | * @throws \OCP\Files\InvalidPathException |
||
1072 | */ |
||
1073 | public function getMimeType($path) { |
||
1077 | |||
1078 | /** |
||
1079 | * @param string $type |
||
1080 | * @param string $path |
||
1081 | * @param bool $raw |
||
1082 | * @return bool|null|string |
||
1083 | */ |
||
1084 | public function hash($type, $path, $raw = false) { |
||
1108 | |||
1109 | /** |
||
1110 | * @param string $path |
||
1111 | * @return mixed |
||
1112 | * @throws \OCP\Files\InvalidPathException |
||
1113 | */ |
||
1114 | public function free_space($path = '/') { |
||
1118 | |||
1119 | /** |
||
1120 | * abstraction layer for basic filesystem functions: wrapper for \OC\Files\Storage\Storage |
||
1121 | * |
||
1122 | * @param string $operation |
||
1123 | * @param string $path |
||
1124 | * @param array $hooks (optional) |
||
1125 | * @param mixed $extraParam (optional) |
||
1126 | * @return mixed |
||
1127 | * @throws \Exception |
||
1128 | * |
||
1129 | * This method takes requests for basic filesystem functions (e.g. reading & writing |
||
1130 | * files), processes hooks and proxies, sanitises paths, and finally passes them on to |
||
1131 | * \OC\Files\Storage\Storage for delegation to a storage backend for execution |
||
1132 | */ |
||
1133 | private function basicOperation($operation, $path, $hooks = [], $extraParam = null) { |
||
1217 | |||
1218 | /** |
||
1219 | * get the path relative to the default root for hook usage |
||
1220 | * |
||
1221 | * @param string $path |
||
1222 | * @return string |
||
1223 | */ |
||
1224 | private function getHookPath($path) { |
||
1230 | |||
1231 | private function shouldEmitHooks($path = '') { |
||
1253 | |||
1254 | /** |
||
1255 | * @param string[] $hooks |
||
1256 | * @param string $path |
||
1257 | * @param bool $post |
||
1258 | * @return bool |
||
1259 | */ |
||
1260 | private function runHooks($hooks, $path, $post = false) { |
||
1292 | |||
1293 | /** |
||
1294 | * check if a file or folder has been updated since $time |
||
1295 | * |
||
1296 | * @param string $path |
||
1297 | * @param int $time |
||
1298 | * @return bool |
||
1299 | */ |
||
1300 | public function hasUpdated($path, $time) { |
||
1303 | |||
1304 | /** |
||
1305 | * @param string $ownerId |
||
1306 | * @return IUser |
||
1307 | */ |
||
1308 | private function getUserObjectForOwner($ownerId) { |
||
1316 | |||
1317 | /** |
||
1318 | * Get file info from cache |
||
1319 | * |
||
1320 | * If the file is not in cached it will be scanned |
||
1321 | * If the file has changed on storage the cache will be updated |
||
1322 | * |
||
1323 | * @param \OC\Files\Storage\Storage $storage |
||
1324 | * @param string $internalPath |
||
1325 | * @param string $relativePath |
||
1326 | * @return array|bool |
||
1327 | */ |
||
1328 | private function getCacheEntry($storage, $internalPath, $relativePath) { |
||
1358 | |||
1359 | /** |
||
1360 | * get the filesystem info |
||
1361 | * |
||
1362 | * @param string $path |
||
1363 | * @param boolean|string $includeMountPoints true to add mountpoint sizes, |
||
1364 | * 'ext' to add only ext storage mount point sizes. Defaults to true. |
||
1365 | * defaults to true |
||
1366 | * @return \OC\Files\FileInfo|false False if file does not exist |
||
1367 | */ |
||
1368 | public function getFileInfo($path, $includeMountPoints = true) { |
||
1421 | |||
1422 | /** |
||
1423 | * get the content of a directory |
||
1424 | * |
||
1425 | * @param string $directory path under datadirectory |
||
1426 | * @param string $mimetype_filter limit returned content to this mimetype or mimepart |
||
1427 | * @return FileInfo[] |
||
1428 | */ |
||
1429 | public function getDirectoryContent($directory, $mimetype_filter = '') { |
||
1556 | |||
1557 | /** |
||
1558 | * change file metadata |
||
1559 | * |
||
1560 | * @param string $path |
||
1561 | * @param array|\OCP\Files\FileInfo $data |
||
1562 | * @return int |
||
1563 | * |
||
1564 | * returns the fileid of the updated file |
||
1565 | */ |
||
1566 | public function putFileInfo($path, $data) { |
||
1590 | |||
1591 | /** |
||
1592 | * search for files with the name matching $query |
||
1593 | * |
||
1594 | * @param string $query |
||
1595 | * @return FileInfo[] |
||
1596 | */ |
||
1597 | public function search($query) { |
||
1600 | |||
1601 | /** |
||
1602 | * search for files with the name matching $query |
||
1603 | * |
||
1604 | * @param string $query |
||
1605 | * @return FileInfo[] |
||
1606 | */ |
||
1607 | public function searchRaw($query) { |
||
1610 | |||
1611 | /** |
||
1612 | * search for files by mimetype |
||
1613 | * |
||
1614 | * @param string $mimetype |
||
1615 | * @return FileInfo[] |
||
1616 | */ |
||
1617 | public function searchByMime($mimetype) { |
||
1620 | |||
1621 | /** |
||
1622 | * search for files by tag |
||
1623 | * |
||
1624 | * @param string|int $tag name or tag id |
||
1625 | * @param string $userId owner of the tags |
||
1626 | * @return FileInfo[] |
||
1627 | */ |
||
1628 | public function searchByTag($tag, $userId) { |
||
1631 | |||
1632 | /** |
||
1633 | * @param string $method cache method |
||
1634 | * @param array $args |
||
1635 | * @return FileInfo[] |
||
1636 | */ |
||
1637 | private function searchCommon($method, $args) { |
||
1681 | |||
1682 | /** |
||
1683 | * Get the owner for a file or folder |
||
1684 | * |
||
1685 | * @param string $path |
||
1686 | * @return string the user id of the owner |
||
1687 | * @throws NotFoundException |
||
1688 | */ |
||
1689 | public function getOwner($path) { |
||
1696 | |||
1697 | /** |
||
1698 | * get the ETag for a file or folder |
||
1699 | * |
||
1700 | * @param string $path |
||
1701 | * @return string |
||
1702 | */ |
||
1703 | public function getETag($path) { |
||
1715 | |||
1716 | /** |
||
1717 | * Get the path of a file by id, relative to the view |
||
1718 | * |
||
1719 | * Note that the resulting path is not guarantied to be unique for the id, multiple paths can point to the same file |
||
1720 | * |
||
1721 | * @param int $id |
||
1722 | * @param bool $includeShares whether to recurse into shared mounts |
||
1723 | * @throws NotFoundException |
||
1724 | * @return string |
||
1725 | */ |
||
1726 | public function getPath($id, $includeShares = true) { |
||
1756 | |||
1757 | /** |
||
1758 | * @param string $path |
||
1759 | * @throws InvalidPathException |
||
1760 | */ |
||
1761 | private function assertPathLength($path) { |
||
1770 | |||
1771 | /** |
||
1772 | * check if it is allowed to move a mount point to a given target. |
||
1773 | * It is not allowed to move a mount point into a different mount point or |
||
1774 | * into an already shared folder |
||
1775 | * |
||
1776 | * @param MoveableMount $mount1 moveable mount |
||
1777 | * @param string $target absolute target path |
||
1778 | * @return boolean |
||
1779 | */ |
||
1780 | private function canMove(MoveableMount $mount1, $target) { |
||
1791 | |||
1792 | /** |
||
1793 | * Get a fileinfo object for files that are ignored in the cache (part files) |
||
1794 | * |
||
1795 | * @param string $path |
||
1796 | * @return \OCP\Files\FileInfo |
||
1797 | */ |
||
1798 | private function getPartFileInfo($path) { |
||
1821 | |||
1822 | /** |
||
1823 | * @param string $path |
||
1824 | * @param string $fileName |
||
1825 | * @throws InvalidPathException |
||
1826 | */ |
||
1827 | public function verifyPath($path, $fileName) { |
||
1870 | |||
1871 | /** |
||
1872 | * get all parent folders of $path |
||
1873 | * |
||
1874 | * @param string $path |
||
1875 | * @return string[] |
||
1876 | */ |
||
1877 | private function getParents($path) { |
||
1897 | |||
1898 | /** |
||
1899 | * Returns the mount point for which to lock |
||
1900 | * |
||
1901 | * @param string $absolutePath absolute path |
||
1902 | * @param bool $useParentMount true to return parent mount instead of whatever |
||
1903 | * is mounted directly on the given path, false otherwise |
||
1904 | * @return \OC\Files\Mount\MountPoint mount point for which to apply locks |
||
1905 | */ |
||
1906 | private function getMountForLock($absolutePath, $useParentMount = false) { |
||
1924 | |||
1925 | /** |
||
1926 | * Lock the given path |
||
1927 | * |
||
1928 | * @param string $path the path of the file to lock, relative to the view |
||
1929 | * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
||
1930 | * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage |
||
1931 | * |
||
1932 | * @return bool False if the path is excluded from locking, true otherwise |
||
1933 | * @throws \OCP\Lock\LockedException if the path is already locked |
||
1934 | */ |
||
1935 | View Code Duplication | private function lockPath($path, $type, $lockMountPoint = false) { |
|
1964 | |||
1965 | /** |
||
1966 | * Change the lock type |
||
1967 | * |
||
1968 | * @param string $path the path of the file to lock, relative to the view |
||
1969 | * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
||
1970 | * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage |
||
1971 | * |
||
1972 | * @return bool False if the path is excluded from locking, true otherwise |
||
1973 | * @throws \OCP\Lock\LockedException if the path is already locked |
||
1974 | */ |
||
1975 | View Code Duplication | public function changeLock($path, $type, $lockMountPoint = false) { |
|
2005 | |||
2006 | /** |
||
2007 | * Unlock the given path |
||
2008 | * |
||
2009 | * @param string $path the path of the file to unlock, relative to the view |
||
2010 | * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
||
2011 | * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage |
||
2012 | * |
||
2013 | * @return bool False if the path is excluded from locking, true otherwise |
||
2014 | */ |
||
2015 | private function unlockPath($path, $type, $lockMountPoint = false) { |
||
2036 | |||
2037 | /** |
||
2038 | * Lock a path and all its parents up to the root of the view |
||
2039 | * |
||
2040 | * @param string $path the path of the file to lock relative to the view |
||
2041 | * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
||
2042 | * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage |
||
2043 | * |
||
2044 | * @return bool False if the path is excluded from locking, true otherwise |
||
2045 | */ |
||
2046 | View Code Duplication | public function lockFile($path, $type, $lockMountPoint = false) { |
|
2062 | |||
2063 | /** |
||
2064 | * Unlock a path and all its parents up to the root of the view |
||
2065 | * |
||
2066 | * @param string $path the path of the file to lock relative to the view |
||
2067 | * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
||
2068 | * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage |
||
2069 | * |
||
2070 | * @return bool False if the path is excluded from locking, true otherwise |
||
2071 | */ |
||
2072 | View Code Duplication | public function unlockFile($path, $type, $lockMountPoint = false) { |
|
2088 | |||
2089 | /** |
||
2090 | * Only lock files in data/user/files/ |
||
2091 | * |
||
2092 | * @param string $path Absolute path to the file/folder we try to (un)lock |
||
2093 | * @return bool |
||
2094 | */ |
||
2095 | protected function shouldLockFile($path) { |
||
2106 | |||
2107 | /** |
||
2108 | * Shortens the given absolute path to be relative to |
||
2109 | * "$user/files". |
||
2110 | * |
||
2111 | * @param string $absolutePath absolute path which is under "files" |
||
2112 | * |
||
2113 | * @return string path relative to "files" with trimmed slashes or null |
||
2114 | * if the path was NOT relative to files |
||
2115 | * |
||
2116 | * @throws \InvalidArgumentException if the given path was not under "files" |
||
2117 | * @since 8.1.0 |
||
2118 | */ |
||
2119 | public function getPathRelativeToFiles($absolutePath) { |
||
2131 | |||
2132 | /** |
||
2133 | * @param string $filename |
||
2134 | * @return array |
||
2135 | * @throws \OC\User\NoUserException |
||
2136 | * @throws NotFoundException |
||
2137 | */ |
||
2138 | public function getUidAndFilename($filename) { |
||
2155 | |||
2156 | /** |
||
2157 | * Creates parent non-existing folders |
||
2158 | * |
||
2159 | * @param string $filePath |
||
2160 | * @return bool |
||
2161 | */ |
||
2162 | private function createParentDirectories($filePath) { |
||
2173 | } |
||
2174 |
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: