]> source.dussan.org Git - nextcloud-server.git/commitdiff
chore: ugly type juggling
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Thu, 8 Jun 2023 21:32:16 +0000 (23:32 +0200)
committerArthur Schiwon <blizzz@arthur-schiwon.de>
Wed, 21 Jun 2023 14:53:20 +0000 (16:53 +0200)
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
lib/private/Files/Cache/QuerySearchHelper.php
lib/private/Files/FileInfo.php
lib/private/Files/Node/Folder.php
lib/private/Files/Node/Node.php
lib/private/Files/Node/Root.php
tests/lib/Files/Node/FolderTest.php

index 52663213b162e496152f0a014807ecceca9a7300..b4376eb2d985cffb045a760aaea6441c6bae1190 100644 (file)
@@ -195,23 +195,33 @@ class QuerySearchHelper {
        }
 
        /**
-        * @return array{array<string, ICache>, array<string, IMountPoint>}
+        * @return list{0?: array<array-key, ICache>, 1?: array<array-key, IMountPoint>}
         */
        public function getCachesAndMountPointsForSearch(IRootFolder $root, string $path, bool $limitToHome = false): array {
                $rootLength = strlen($path);
-               $mount = $root->getMount($path);
-               $storage = $mount->getStorage();
+               $storage = null;
+               if (method_exists($root, 'getMount')) {
+                       /** @var IMountPoint $mount */
+                       $mount = $root->getMount($path);
+                       $storage = $mount->getStorage();
+               }
+               if ($storage === null) {
+                       return [];
+               }
                $internalPath = $mount->getInternalPath($path);
 
                if ($internalPath !== '') {
                        // a temporary CacheJail is used to handle filtering down the results to within this folder
+                       /** @var ICache[] $caches */
                        $caches = ['' => new CacheJail($storage->getCache(''), $internalPath)];
                } else {
+                       /** @var ICache[] $caches */
                        $caches = ['' => $storage->getCache('')];
                }
+               /** @var IMountPoint[] $mountByMountPoint */
                $mountByMountPoint = ['' => $mount];
 
-               if (!$limitToHome) {
+               if (!$limitToHome && method_exists($root, 'getMountsIn')) {
                        /** @var IMountPoint[] $mounts */
                        $mounts = $root->getMountsIn($path);
                        foreach ($mounts as $mount) {
index d9b773cc2a660edae7ffdb5ba689d79bfe695d0e..2b6b83a25462cc564ae812e408685a403e364472 100644 (file)
@@ -143,9 +143,6 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
                return $this->path;
        }
 
-       /**
-        * @return \OCP\Files\Storage
-        */
        public function getStorage() {
                return $this->storage;
        }
index 44f47e92ca0f85d7684854ec5a4fc5885ca0d075..9714a0aea00d4f6ad39c445d84c9c2a03ff0e002 100644 (file)
@@ -330,8 +330,13 @@ class Folder extends Node implements \OCP\Files\Folder {
         * @return array
         */
        protected function getByIdInRootMount(int $id): array {
-               $mount = $this->root->getMount('');
-               $cacheEntry = $mount->getStorage()->getCache($this->path)->get($id);
+               $storage = null;
+               if (\method_exists($this->root, 'getMount')) {
+                       /** @var IMountPoint $mount */
+                       $mount = $this->root->getMount('');
+                       $storage = $mount->getStorage();
+               }
+               $cacheEntry = $storage?->getCache($this->path)->get($id);
                if (!$cacheEntry) {
                        return [];
                }
@@ -346,7 +351,7 @@ class Folder extends Node implements \OCP\Files\Folder {
                return [$this->root->createNode(
                        $absolutePath, new \OC\Files\FileInfo(
                                $absolutePath,
-                               $mount->getStorage(),
+                               $storage,
                                $cacheEntry->getPath(),
                                $cacheEntry,
                                $mount
index 4804f7046aa4ee25767b70bce80e94d9599da6a3..4ba2c472c674a648f04029b9a130d6098aa1939d 100644 (file)
@@ -35,6 +35,7 @@ use OC\Files\Utils\PathHelper;
 use OCP\Files\FileInfo;
 use OCP\Files\InvalidPathException;
 use OCP\Files\IRootFolder;
+use OCP\Files\Node as INode;
 use OCP\Files\NotFoundException;
 use OCP\Files\NotPermittedException;
 use OCP\Lock\LockedException;
@@ -42,7 +43,7 @@ use OCP\PreConditionNotMetException;
 use Symfony\Component\EventDispatcher\GenericEvent;
 
 // FIXME: this class really should be abstract
-class Node implements \OCP\Files\Node {
+class Node implements INode {
        /**
         * @var \OC\Files\View $view
         */
@@ -128,7 +129,9 @@ class Node implements \OCP\Files\Node {
                $args = !empty($args) ? $args : [$this];
                $dispatcher = \OC::$server->getEventDispatcher();
                foreach ($hooks as $hook) {
-                       $this->root->emit('\OC\Files', $hook, $args);
+                       if (method_exists($this->root, 'emit')) {
+                               $this->root->emit('\OC\Files', $hook, $args);
+                       }
                        $dispatcher->dispatch('\OCP\Files::' . $hook, new GenericEvent($args));
                }
        }
@@ -288,10 +291,7 @@ class Node implements \OCP\Files\Node {
                return $this->getFileInfo(false)->isCreatable();
        }
 
-       /**
-        * @return Node
-        */
-       public function getParent() {
+       public function getParent(): INode|IRootFolder {
                if ($this->parent === null) {
                        $newPath = dirname($this->path);
                        if ($newPath === '' || $newPath === '.' || $newPath === '/') {
@@ -400,7 +400,7 @@ class Node implements \OCP\Files\Node {
 
        /**
         * @param string $targetPath
-        * @return \OCP\Files\Node
+        * @return INode
         * @throws InvalidPathException
         * @throws NotFoundException
         * @throws NotPermittedException if copy not allowed or failed
@@ -426,7 +426,7 @@ class Node implements \OCP\Files\Node {
 
        /**
         * @param string $targetPath
-        * @return \OCP\Files\Node
+        * @return INode
         * @throws InvalidPathException
         * @throws NotFoundException
         * @throws NotPermittedException if move not allowed or failed
index e9fb14e5364b9199466d09ff77a54041288f38e2..0ed1bcab2aedfa75d5f6dbd3819037ec90e716cc 100644 (file)
@@ -45,6 +45,7 @@ use OCP\Files\Config\IUserMountCache;
 use OCP\Files\Events\Node\FilesystemTornDownEvent;
 use OCP\Files\IRootFolder;
 use OCP\Files\Mount\IMountPoint;
+use OCP\Files\Node as INode;
 use OCP\Files\NotFoundException;
 use OCP\Files\NotPermittedException;
 use OCP\IUser;
@@ -339,10 +340,9 @@ class Root extends Folder implements IRootFolder {
        }
 
        /**
-        * @return Node
         * @throws \OCP\Files\NotFoundException
         */
-       public function getParent() {
+       public function getParent(): INode|IRootFolder {
                throw new NotFoundException();
        }
 
index d745a05ba17f42832defe756fa6b19573e1f8901..0bcf69c5c13039fe174ac1ac0363b20700db5efa 100644 (file)
@@ -24,6 +24,7 @@ use OC\Files\Search\SearchQuery;
 use OC\Files\Storage\Temporary;
 use OC\Files\Storage\Wrapper\Jail;
 use OCP\Files\Cache\ICacheEntry;
+use OCP\Files\IRootFolder;
 use OCP\Files\Mount\IMountPoint;
 use OCP\Files\NotFoundException;
 use OCP\Files\Search\ISearchComparison;
@@ -462,12 +463,13 @@ class FolderTest extends NodeTest {
        }
 
        public function testIsSubNode() {
-               $file = new Node(null, $this->view, '/foo/bar');
-               $folder = new Folder(null, $this->view, '/foo');
+               $rootFolderMock = $this->createMock(IRootFolder::class);
+               $file = new Node($rootFolderMock, $this->view, '/foo/bar');
+               $folder = new Folder($rootFolderMock, $this->view, '/foo');
                $this->assertTrue($folder->isSubNode($file));
                $this->assertFalse($folder->isSubNode($folder));
 
-               $file = new Node(null, $this->view, '/foobar');
+               $file = new Node($rootFolderMock, $this->view, '/foobar');
                $this->assertFalse($folder->isSubNode($file));
        }