From f55afafc58107a4f8841569fda621f85e441e88b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 30 Jan 2026 17:38:56 +0100 Subject: [PATCH 1/3] fix: getById: don't setup for all users with access by default Signed-off-by: Robin Appelman --- lib/private/Files/Mount/Manager.php | 4 ++-- lib/private/Files/Node/Root.php | 36 +++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/lib/private/Files/Mount/Manager.php b/lib/private/Files/Mount/Manager.php index b763697387dd7..72b38f38575b7 100644 --- a/lib/private/Files/Mount/Manager.php +++ b/lib/private/Files/Mount/Manager.php @@ -230,11 +230,11 @@ public function getSetupManager(): SetupManager { } /** - * Return all mounts in a path from a specific mount provider + * Return all mounts in a path from a specific mount provider, indexed by mount point * * @param string $path * @param string[] $mountProviders - * @return IMountPoint[] + * @return array */ public function getMountsByMountProvider(string $path, array $mountProviders) { $this->getSetupManager()->setupForProvider($path, $mountProviders); diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php index c94eadcedb3f6..20e1f4c382ecb 100644 --- a/lib/private/Files/Node/Root.php +++ b/lib/private/Files/Node/Root.php @@ -5,6 +5,7 @@ * SPDX-FileCopyrightText: 2016 ownCloud, Inc. * SPDX-License-Identifier: AGPL-3.0-only */ + namespace OC\Files\Node; use OC\Files\FileInfo; @@ -19,6 +20,8 @@ use OCP\Cache\CappedMemoryCache; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Cache\ICacheEntry; +use OCP\Files\Config\ICachedMountFileInfo; +use OCP\Files\Config\ICachedMountInfo; use OCP\Files\Config\IUserMountCache; use OCP\Files\Events\Node\FilesystemTornDownEvent; use OCP\Files\IRootFolder; @@ -82,10 +85,8 @@ public function __construct( /** * Get the user for which the filesystem is setup - * - * @return \OC\User\User */ - public function getUser() { + public function getUser(): ?IUser { return $this->user; } @@ -411,12 +412,12 @@ public function getByIdInPath(int $id, string $path): array { } else { $user = null; } - $mountsContainingFile = $mountCache->getMountsForFileId($id, $user); + $mountInfosContainingFiles = $mountCache->getMountsForFileId($id, $user); // if the mount isn't in the cache yet, perform a setup first, then try again - if (count($mountsContainingFile) === 0) { + if (count($mountInfosContainingFiles) === 0) { $setupManager->setupForPath($path, true); - $mountsContainingFile = $mountCache->getMountsForFileId($id, $user); + $mountInfosContainingFiles = $mountCache->getMountsForFileId($id, $user); } // when a user has access through the same storage through multiple paths @@ -428,16 +429,31 @@ public function getByIdInPath(int $id, string $path): array { $mountRootIds = array_map(function ($mount) { return $mount->getRootId(); - }, $mountsContainingFile); + }, $mountInfosContainingFiles); $mountRootPaths = array_map(function ($mount) { return $mount->getRootInternalPath(); - }, $mountsContainingFile); + }, $mountInfosContainingFiles); $mountProviders = array_unique(array_map(function ($mount) { return $mount->getMountProvider(); - }, $mountsContainingFile)); + }, $mountInfosContainingFiles)); + $mountPoints = array_map(fn (ICachedMountInfo $mountInfo) => $mountInfo->getMountPoint(), $mountInfosContainingFiles); $mountRoots = array_combine($mountRootIds, $mountRootPaths); - $mountsContainingFile = array_filter(array_map($this->mountManager->getMountFromMountInfo(...), $mountsContainingFile)); + $mounts = $this->mountManager->getMountsByMountProvider($path, $mountProviders); + $mountsContainingFile = array_filter($mounts, fn (IMountPoint $mount) => in_array($mount->getMountPoint(), $mountPoints)); + + if (count($mountsContainingFile) == 0 && count($mountInfosContainingFiles) > 0) { + if (!$user) { + $user = $this->getUser()?->getUID(); + } + if (!$user) { + /** @var ICachedMountFileInfo $firstMount */ + $firstMount = current($mountInfosContainingFiles); + $user = $firstMount->getUser()->getUID(); + } + $mountInfosContainingFiles = array_filter($mountInfosContainingFiles, fn (ICachedMountInfo $mountInfo) => $mountInfo->getUser()->getUID() === $user); + $mountsContainingFile = array_filter(array_map($this->mountManager->getMountFromMountInfo(...), $mountInfosContainingFiles)); + } if (count($mountsContainingFile) === 0) { if ($user === $this->getAppDataDirectoryName()) { From 0496d1332c1dd5eb5e739825b191dc9fa0340755 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 2 Feb 2026 18:10:00 +0100 Subject: [PATCH 2/3] test: adjust tests to updated getById Signed-off-by: Robin Appelman --- tests/lib/Files/Node/FolderTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php index 19374fee6c128..e0ed345049bf1 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -541,6 +541,8 @@ public function testGetById(): void { $manager->method('getMountFromMountInfo') ->willReturn($mount); + $manager->method('getMountsByMountProvider') + ->willReturn([$mount]); $node = new Folder($root, $view, '/bar/foo'); $result = $node->getById(1); @@ -586,6 +588,8 @@ public function testGetByIdMountRoot(): void { $manager->method('getMountFromMountInfo') ->willReturn($mount); + $manager->method('getMountsByMountProvider') + ->willReturn([$mount]); $node = new Folder($root, $view, '/bar'); $result = $node->getById(1); @@ -631,6 +635,8 @@ public function testGetByIdOutsideFolder(): void { $manager->method('getMountFromMountInfo') ->willReturn($mount); + $manager->method('getMountsByMountProvider') + ->willReturn([$mount]); $node = new Folder($root, $view, '/bar/foo'); $result = $node->getById(1); @@ -694,6 +700,8 @@ public function testGetByIdMultipleStorages(): void { } return null; }); + $manager->method('getMountsByMountProvider') + ->willReturn([$mount1, $mount2]); $node = new Folder($root, $view, '/bar/foo'); $result = $node->getById(1); From 34448dd1639b03838b7f9c6cbfc3d6ea02230420 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 2 Feb 2026 19:17:27 +0100 Subject: [PATCH 3/3] chore: update psalm baseline Signed-off-by: Robin Appelman --- build/psalm-baseline.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 371f575b9a25e..9dc7e8e71c321 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -3781,17 +3781,12 @@ mountManager->findByNumericId($numericId)]]> mountManager->findByStorageId($storageId)]]> mountManager->findIn($mountPoint)]]> - user]]> - - - user]]> -