From 5640339d1d6d87a80b3640b7c1465b63d53352e5 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 3 Jun 2023 01:19:15 +0200 Subject: [PATCH 1/8] fix: expect interface, not a specific implementation - fixes a regression when deleting folders while music app was enabled, for a LazyRoot was passed to this method. Signed-off-by: Arthur Schiwon --- lib/private/Files/Cache/QuerySearchHelper.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/private/Files/Cache/QuerySearchHelper.php b/lib/private/Files/Cache/QuerySearchHelper.php index 695fbcd0717d7..6a78f585c48c4 100644 --- a/lib/private/Files/Cache/QuerySearchHelper.php +++ b/lib/private/Files/Cache/QuerySearchHelper.php @@ -26,15 +26,14 @@ namespace OC\Files\Cache; use OC\Files\Cache\Wrapper\CacheJail; -use OC\Files\Node\Root; use OC\Files\Search\QueryOptimizer\QueryOptimizer; use OC\Files\Search\SearchBinaryOperator; use OC\SystemConfig; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\Cache\ICache; use OCP\Files\Cache\ICacheEntry; -use OCP\Files\Folder; use OCP\Files\IMimeTypeLoader; +use OCP\Files\IRootFolder; use OCP\Files\Mount\IMountPoint; use OCP\Files\Search\ISearchBinaryOperator; use OCP\Files\Search\ISearchQuery; @@ -199,7 +198,7 @@ public function searchInCaches(ISearchQuery $searchQuery, array $caches): array /** * @return array{array, array} */ - public function getCachesAndMountPointsForSearch(Root $root, string $path, bool $limitToHome = false): array { + public function getCachesAndMountPointsForSearch(IRootFolder $root, string $path, bool $limitToHome = false): array { $rootLength = strlen($path); $mount = $root->getMount($path); $storage = $mount->getStorage(); From e5e9df2948e32d1fedbf3c0f3e0b87e42e361128 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 3 Jun 2023 01:34:06 +0200 Subject: [PATCH 2/8] fix: add typehine for IRootFolder Signed-off-by: Arthur Schiwon --- lib/private/Files/Node/Node.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/private/Files/Node/Node.php b/lib/private/Files/Node/Node.php index 161b3e2dd3022..9a1630ebde020 100644 --- a/lib/private/Files/Node/Node.php +++ b/lib/private/Files/Node/Node.php @@ -34,6 +34,7 @@ use OC\Files\Utils\PathHelper; use OCP\Files\FileInfo; use OCP\Files\InvalidPathException; +use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OCP\Lock\LockedException; @@ -47,10 +48,7 @@ class Node implements \OCP\Files\Node { */ protected $view; - /** - * @var \OC\Files\Node\Root $root - */ - protected $root; + protected IRootFolder $root; /** * @var string $path Absolute path to the node (e.g. /admin/files/folder/file) @@ -396,7 +394,7 @@ public function unlock($type) { /** * @param string $targetPath - * @return \OC\Files\Node\Node + * @return \OCP\Files\Node * @throws InvalidPathException * @throws NotFoundException * @throws NotPermittedException if copy not allowed or failed @@ -422,7 +420,7 @@ public function copy($targetPath) { /** * @param string $targetPath - * @return \OC\Files\Node\Node + * @return \OCP\Files\Node * @throws InvalidPathException * @throws NotFoundException * @throws NotPermittedException if move not allowed or failed From d5b69c16984163ba0f8c0a8001cf31fbba167b5f Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 8 Jun 2023 23:32:16 +0200 Subject: [PATCH 3/8] chore: ugly type juggling Signed-off-by: Arthur Schiwon --- lib/private/Files/Cache/QuerySearchHelper.php | 18 ++++++++++++++---- lib/private/Files/FileInfo.php | 3 --- lib/private/Files/Node/Folder.php | 11 ++++++++--- lib/private/Files/Node/Node.php | 16 ++++++++-------- lib/private/Files/Node/Root.php | 4 ++-- tests/lib/Files/Node/FolderTest.php | 8 +++++--- 6 files changed, 37 insertions(+), 23 deletions(-) diff --git a/lib/private/Files/Cache/QuerySearchHelper.php b/lib/private/Files/Cache/QuerySearchHelper.php index 6a78f585c48c4..a17cc02d37b34 100644 --- a/lib/private/Files/Cache/QuerySearchHelper.php +++ b/lib/private/Files/Cache/QuerySearchHelper.php @@ -196,23 +196,33 @@ public function searchInCaches(ISearchQuery $searchQuery, array $caches): array } /** - * @return array{array, array} + * @return list{0?: array, 1?: array} */ 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) { diff --git a/lib/private/Files/FileInfo.php b/lib/private/Files/FileInfo.php index 47c893ebbf153..70f700d2d7339 100644 --- a/lib/private/Files/FileInfo.php +++ b/lib/private/Files/FileInfo.php @@ -149,9 +149,6 @@ public function getPath() { return $this->path; } - /** - * @return \OCP\Files\Storage - */ public function getStorage() { return $this->storage; } diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index e6bae29807dd6..79a8b88fc88e0 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -329,8 +329,13 @@ protected function getAppDataDirectoryName(): string { * @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 []; } @@ -345,7 +350,7 @@ protected function getByIdInRootMount(int $id): array { return [$this->root->createNode( $absolutePath, new \OC\Files\FileInfo( $absolutePath, - $mount->getStorage(), + $storage, $cacheEntry->getPath(), $cacheEntry, $mount diff --git a/lib/private/Files/Node/Node.php b/lib/private/Files/Node/Node.php index 9a1630ebde020..7c8c019783407 100644 --- a/lib/private/Files/Node/Node.php +++ b/lib/private/Files/Node/Node.php @@ -35,6 +35,7 @@ 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 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 */ @@ -122,7 +123,9 @@ protected function sendHooks($hooks, array $args = null) { $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)); } } @@ -282,10 +285,7 @@ public function isCreatable() { return $this->getFileInfo()->isCreatable(); } - /** - * @return Node - */ - public function getParent() { + public function getParent(): INode|IRootFolder { if ($this->parent === null) { $newPath = dirname($this->path); if ($newPath === '' || $newPath === '.' || $newPath === '/') { @@ -394,7 +394,7 @@ public function unlock($type) { /** * @param string $targetPath - * @return \OCP\Files\Node + * @return INode * @throws InvalidPathException * @throws NotFoundException * @throws NotPermittedException if copy not allowed or failed @@ -420,7 +420,7 @@ public function copy($targetPath) { /** * @param string $targetPath - * @return \OCP\Files\Node + * @return INode * @throws InvalidPathException * @throws NotFoundException * @throws NotPermittedException if move not allowed or failed diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php index ca930c1002c0f..2de71c1500e6c 100644 --- a/lib/private/Files/Node/Root.php +++ b/lib/private/Files/Node/Root.php @@ -45,6 +45,7 @@ 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 @@ public function isShareable() { } /** - * @return Node * @throws \OCP\Files\NotFoundException */ - public function getParent() { + public function getParent(): INode|IRootFolder { throw new NotFoundException(); } diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php index d745a05ba17f4..0bcf69c5c1303 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -24,6 +24,7 @@ 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 @@ public function testSearchSubStorages() { } 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)); } From 481cbafae30dc5fdaa44615a898375be3b0cd89f Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 15 Jun 2023 23:21:56 +0200 Subject: [PATCH 4/8] refactor: declare getMount() and getMountsIn() at IRootFolder Signed-off-by: Arthur Schiwon --- lib/private/Files/Cache/QuerySearchHelper.php | 11 +++-------- lib/private/Files/Node/Folder.php | 8 ++------ lib/private/Files/Node/LazyFolder.php | 7 ++++--- lib/private/Files/Node/Root.php | 8 ++------ lib/public/Files/IRootFolder.php | 13 +++++++++++++ 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/lib/private/Files/Cache/QuerySearchHelper.php b/lib/private/Files/Cache/QuerySearchHelper.php index a17cc02d37b34..c149276cf5a3c 100644 --- a/lib/private/Files/Cache/QuerySearchHelper.php +++ b/lib/private/Files/Cache/QuerySearchHelper.php @@ -200,12 +200,8 @@ public function searchInCaches(ISearchQuery $searchQuery, array $caches): array */ public function getCachesAndMountPointsForSearch(IRootFolder $root, string $path, bool $limitToHome = false): array { $rootLength = strlen($path); - $storage = null; - if (method_exists($root, 'getMount')) { - /** @var IMountPoint $mount */ - $mount = $root->getMount($path); - $storage = $mount->getStorage(); - } + $mount = $root->getMount($path); + $storage = $mount->getStorage(); if ($storage === null) { return []; } @@ -222,8 +218,7 @@ public function getCachesAndMountPointsForSearch(IRootFolder $root, string $path /** @var IMountPoint[] $mountByMountPoint */ $mountByMountPoint = ['' => $mount]; - if (!$limitToHome && method_exists($root, 'getMountsIn')) { - /** @var IMountPoint[] $mounts */ + if (!$limitToHome) { $mounts = $root->getMountsIn($path); foreach ($mounts as $mount) { $storage = $mount->getStorage(); diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index 79a8b88fc88e0..9e443105ae4bf 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -329,12 +329,8 @@ protected function getAppDataDirectoryName(): string { * @return array */ protected function getByIdInRootMount(int $id): array { - $storage = null; - if (\method_exists($this->root, 'getMount')) { - /** @var IMountPoint $mount */ - $mount = $this->root->getMount(''); - $storage = $mount->getStorage(); - } + $mount = $this->root->getMount(''); + $storage = $mount->getStorage(); $cacheEntry = $storage?->getCache($this->path)->get($id); if (!$cacheEntry) { return []; diff --git a/lib/private/Files/Node/LazyFolder.php b/lib/private/Files/Node/LazyFolder.php index 1bae0f52e5915..fc17ed2eb52b4 100644 --- a/lib/private/Files/Node/LazyFolder.php +++ b/lib/private/Files/Node/LazyFolder.php @@ -28,6 +28,7 @@ use OC\Files\Utils\PathHelper; use OCP\Constants; +use OCP\Files\Mount\IMountPoint; /** * Class LazyFolder @@ -110,14 +111,14 @@ public function mount($storage, $mountPoint, $arguments = []) { /** * @inheritDoc */ - public function getMount($mountPoint) { + public function getMount(string $mountPoint): IMountPoint { return $this->__call(__FUNCTION__, func_get_args()); } /** - * @inheritDoc + * @return IMountPoint[] */ - public function getMountsIn($mountPoint) { + public function getMountsIn(string $mountPoint): array { return $this->__call(__FUNCTION__, func_get_args()); } diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php index 2de71c1500e6c..6b82c9f7250a8 100644 --- a/lib/private/Files/Node/Root.php +++ b/lib/private/Files/Node/Root.php @@ -154,11 +154,7 @@ public function mount($storage, $mountPoint, $arguments = []) { $this->mountManager->addMount($mount); } - /** - * @param string $mountPoint - * @return \OC\Files\Mount\MountPoint - */ - public function getMount($mountPoint) { + public function getMount(string $mountPoint): IMountPoint { return $this->mountManager->find($mountPoint); } @@ -166,7 +162,7 @@ public function getMount($mountPoint) { * @param string $mountPoint * @return \OC\Files\Mount\MountPoint[] */ - public function getMountsIn($mountPoint) { + public function getMountsIn(string $mountPoint): array { return $this->mountManager->findIn($mountPoint); } diff --git a/lib/public/Files/IRootFolder.php b/lib/public/Files/IRootFolder.php index 7d007cb690cdb..c3a0694bdc458 100644 --- a/lib/public/Files/IRootFolder.php +++ b/lib/public/Files/IRootFolder.php @@ -26,6 +26,7 @@ use OC\Hooks\Emitter; use OC\User\NoUserException; +use OCP\Files\Mount\IMountPoint; /** * Interface IRootFolder @@ -56,4 +57,16 @@ public function getUserFolder($userId); * @since 24.0.0 */ public function getByIdInPath(int $id, string $path); + + /** + * @return IMountPoint[] + * + * @since 28.0.0 + */ + public function getMountsIn(string $mountPoint): array; + + /** + * @since 28.0.0 + */ + public function getMount(string $mountPoint): IMountPoint; } From c2fdee7f6e790051c1a9118ba5a7dfc4619c2711 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 17 Jun 2023 00:15:49 +0200 Subject: [PATCH 5/8] ci: pro forma check of existence of internal method createNode() is protected and used by Folder, but being an internal-only method it shall not be exposed in the Folder or IRootFolder interface. Signed-off-by: Arthur Schiwon --- lib/private/Files/Node/Folder.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index 9e443105ae4bf..4f5ac07a15ad0 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -39,6 +39,7 @@ use OCP\Files\Cache\ICacheEntry; use OCP\Files\FileInfo; use OCP\Files\Mount\IMountPoint; +use OCP\Files\Node as INode; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OCP\Files\Search\ISearchBinaryOperator; @@ -108,12 +109,7 @@ public function getDirectoryListing() { }, $folderContent); } - /** - * @param string $path - * @param FileInfo $info - * @return File|Folder - */ - protected function createNode($path, FileInfo $info = null) { + protected function createNode(string $path, ?FileInfo $info = null, bool $infoHasSubMountsIncluded = true): INode { if (is_null($info)) { $isDir = $this->view->is_dir($path); } else { @@ -329,6 +325,12 @@ protected function getAppDataDirectoryName(): string { * @return array */ protected function getByIdInRootMount(int $id): array { + if (!method_exists($this->root, 'createNode')) { + // Always expected to be false. Being a method of Folder, this is + // always implemented. For it is an internal method and should not + // be exposed and made public, it is not part of an interface. + return []; + } $mount = $this->root->getMount(''); $storage = $mount->getStorage(); $cacheEntry = $storage?->getCache($this->path)->get($id); @@ -384,7 +386,7 @@ public function getNonExistingName($name) { /** * @param int $limit * @param int $offset - * @return \OCP\Files\Node[] + * @return INode[] */ public function getRecent($limit, $offset = 0) { $filterOutNonEmptyFolder = new SearchBinaryOperator( From 5ca35c90074a4b4f41a981842764fc4b597db25f Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 26 Jun 2023 14:49:16 +0200 Subject: [PATCH 6/8] docs: adjust @since version to backport Signed-off-by: Arthur Schiwon --- lib/public/Files/IRootFolder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/public/Files/IRootFolder.php b/lib/public/Files/IRootFolder.php index c3a0694bdc458..7b232067554eb 100644 --- a/lib/public/Files/IRootFolder.php +++ b/lib/public/Files/IRootFolder.php @@ -61,12 +61,12 @@ public function getByIdInPath(int $id, string $path); /** * @return IMountPoint[] * - * @since 28.0.0 + * @since 25.0.9 */ public function getMountsIn(string $mountPoint): array; /** - * @since 28.0.0 + * @since 25.0.9 */ public function getMount(string $mountPoint): IMountPoint; } From 2930f890d64c525f437154e2a18a152f9b52cfbe Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 26 Jun 2023 17:07:21 +0200 Subject: [PATCH 7/8] ci: adjust return annotation to older psalm version Signed-off-by: Arthur Schiwon --- lib/private/Files/Cache/QuerySearchHelper.php | 2 +- lib/private/Files/Node/Folder.php | 2 ++ lib/private/SystemTag/SystemTagsInFilesDetector.php | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/private/Files/Cache/QuerySearchHelper.php b/lib/private/Files/Cache/QuerySearchHelper.php index c149276cf5a3c..f3401f7a9b678 100644 --- a/lib/private/Files/Cache/QuerySearchHelper.php +++ b/lib/private/Files/Cache/QuerySearchHelper.php @@ -196,7 +196,7 @@ public function searchInCaches(ISearchQuery $searchQuery, array $caches): array } /** - * @return list{0?: array, 1?: array} + * @return array{0?: array, 1?: array} */ public function getCachesAndMountPointsForSearch(IRootFolder $root, string $path, bool $limitToHome = false): array { $rootLength = strlen($path); diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index 4f5ac07a15ad0..b376d4673e411 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -230,6 +230,8 @@ public function search($query) { /** @var QuerySearchHelper $searchHelper */ $searchHelper = \OC::$server->get(QuerySearchHelper::class); + /** @var \OCP\Files\Cache\ICache[] $caches */ + /** @var \OCP\Files\Mount\IMountPoint[] $mountByMountPoint */ [$caches, $mountByMountPoint] = $searchHelper->getCachesAndMountPointsForSearch($this->root, $this->path, $limitToHome); $resultsPerCache = $searchHelper->searchInCaches($query, $caches); diff --git a/lib/private/SystemTag/SystemTagsInFilesDetector.php b/lib/private/SystemTag/SystemTagsInFilesDetector.php index a214bd77e7bb2..cf7f8d5992d10 100644 --- a/lib/private/SystemTag/SystemTagsInFilesDetector.php +++ b/lib/private/SystemTag/SystemTagsInFilesDetector.php @@ -57,6 +57,7 @@ public function detectAssignedSystemTagsIn( } $query = new SearchQuery($operator, $limit, $offset, []); + /** @var \OCP\Files\Cache\ICache[] $caches */ [$caches, ] = $this->searchHelper->getCachesAndMountPointsForSearch( $this->getRootFolder($folder), $folder->getPath(), From 1eb9f1874d37b024f4faa0636dbfd961c803490e Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 4 Jul 2023 23:36:06 +0200 Subject: [PATCH 8/8] fix: adjust to PHP level and codebase Signed-off-by: Arthur Schiwon --- lib/private/Files/Node/Folder.php | 6 +++--- lib/private/Files/Node/Node.php | 8 ++++++-- lib/private/Files/Node/Root.php | 3 ++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index b376d4673e411..5669f2a4b4599 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -109,7 +109,7 @@ public function getDirectoryListing() { }, $folderContent); } - protected function createNode(string $path, ?FileInfo $info = null, bool $infoHasSubMountsIncluded = true): INode { + protected function createNode(string $path, ?FileInfo $info = null): INode { if (is_null($info)) { $isDir = $this->view->is_dir($path); } else { @@ -326,7 +326,7 @@ protected function getAppDataDirectoryName(): string { * @param int $id * @return array */ - protected function getByIdInRootMount(int $id): array { + protected function getByIdInRootMount(int $id): array { if (!method_exists($this->root, 'createNode')) { // Always expected to be false. Being a method of Folder, this is // always implemented. For it is an internal method and should not @@ -335,7 +335,7 @@ protected function getByIdInRootMount(int $id): array { } $mount = $this->root->getMount(''); $storage = $mount->getStorage(); - $cacheEntry = $storage?->getCache($this->path)->get($id); + $cacheEntry = $storage ? $storage->getCache($this->path)->get($id) : null; if (!$cacheEntry) { return []; } diff --git a/lib/private/Files/Node/Node.php b/lib/private/Files/Node/Node.php index 7c8c019783407..5af317b2a498f 100644 --- a/lib/private/Files/Node/Node.php +++ b/lib/private/Files/Node/Node.php @@ -72,7 +72,7 @@ class Node implements INode { * @param string $path * @param FileInfo $fileInfo */ - public function __construct($root, $view, $path, $fileInfo = null, ?Node $parent = null) { + public function __construct(IRootFolder $root, $view, $path, $fileInfo = null, ?Node $parent = null) { if (Filesystem::normalizePath($view->getRoot()) !== '/') { throw new PreConditionNotMetException('The view passed to the node should not have any fake root set'); } @@ -285,7 +285,11 @@ public function isCreatable() { return $this->getFileInfo()->isCreatable(); } - public function getParent(): INode|IRootFolder { + /** + * @return INode|IRootFolder + * @throws NotFoundException + */ + public function getParent() { if ($this->parent === null) { $newPath = dirname($this->path); if ($newPath === '' || $newPath === '.' || $newPath === '/') { diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php index 6b82c9f7250a8..e102d993c1084 100644 --- a/lib/private/Files/Node/Root.php +++ b/lib/private/Files/Node/Root.php @@ -336,9 +336,10 @@ public function isShareable() { } /** + * @return INode|IRootFolder * @throws \OCP\Files\NotFoundException */ - public function getParent(): INode|IRootFolder { + public function getParent() { throw new NotFoundException(); }