Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions lib/private/Files/Node/Root.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ public function getFirstNodeByIdInPath(int $id, string $path): ?INode {
*/
public function getByIdInPath(int $id, string $path): array {
$mountCache = $this->getUserMountCache();
$setupManager = $this->mountManager->getSetupManager();
if ($path !== '' && strpos($path, '/', 1) > 0) {
[, $user] = explode('/', $path);
} else {
Expand All @@ -414,7 +415,7 @@ public function getByIdInPath(int $id, string $path): array {

// if the mount isn't in the cache yet, perform a setup first, then try again
if (count($mountsContainingFile) === 0) {
$this->mountManager->getSetupManager()->setupForPath($path, true);
$setupManager->setupForPath($path, true);
$mountsContainingFile = $mountCache->getMountsForFileId($id, $user);
}

Expand All @@ -436,11 +437,7 @@ public function getByIdInPath(int $id, string $path): array {
}, $mountsContainingFile));
$mountRoots = array_combine($mountRootIds, $mountRootPaths);

$mounts = $this->mountManager->getMountsByMountProvider($path, $mountProviders);

$mountsContainingFile = array_filter($mounts, function ($mount) use ($mountRoots) {
return isset($mountRoots[$mount->getStorageRootId()]);
});
$mountsContainingFile = array_filter(array_map($this->mountManager->getMountFromMountInfo(...), $mountsContainingFile));

if (count($mountsContainingFile) === 0) {
if ($user === $this->getAppDataDirectoryName()) {
Expand Down
6 changes: 3 additions & 3 deletions lib/private/Files/SetupManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,8 @@ public function setupRoot(): void {
* @param string $path
* @return IUser|null
*/
private function getUserForPath(string $path): ?IUser {
if ($path === '' || $path === '/') {
private function getUserForPath(string $path, bool $includeChildren = false): ?IUser {
if (($path === '' || $path === '/') && !$includeChildren) {
return null;
} elseif (str_starts_with($path, '/__groupfolders')) {
return null;
Expand All @@ -459,7 +459,7 @@ private function getUserForPath(string $path): ?IUser {
* children mounts.
*/
public function setupForPath(string $path, bool $includeChildren = false): void {
$user = $this->getUserForPath($path);
$user = $this->getUserForPath($path, $includeChildren);
if (!$user) {
$this->setupRoot();
return;
Expand Down
34 changes: 26 additions & 8 deletions tests/lib/Files/Node/FolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OC\Files\View;
use OCP\Constants;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Config\ICachedMountInfo;
use OCP\Files\InvalidPathException;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountPoint;
Expand Down Expand Up @@ -538,8 +539,8 @@ public function testGetById(): void {
->with('/bar/foo')
->willReturn([]);

$manager->method('getMountsByMountProvider')
->willReturn([$mount]);
$manager->method('getMountFromMountInfo')
->willReturn($mount);

$node = new Folder($root, $view, '/bar/foo');
$result = $node->getById(1);
Expand Down Expand Up @@ -583,8 +584,8 @@ public function testGetByIdMountRoot(): void {
->with(1)
->willReturn($fileInfo);

$manager->method('getMountsByMountProvider')
->willReturn([$mount]);
$manager->method('getMountFromMountInfo')
->willReturn($mount);

$node = new Folder($root, $view, '/bar');
$result = $node->getById(1);
Expand Down Expand Up @@ -628,8 +629,8 @@ public function testGetByIdOutsideFolder(): void {
->with(1)
->willReturn($fileInfo);

$manager->method('getMountsByMountProvider')
->willReturn([$mount]);
$manager->method('getMountFromMountInfo')
->willReturn($mount);

$node = new Folder($root, $view, '/bar/foo');
$result = $node->getById(1);
Expand Down Expand Up @@ -668,14 +669,31 @@ public function testGetByIdMultipleStorages(): void {
1,
''
),
new CachedMountInfo(
$this->user,
1,
0,
'/bar/foo/asd/',
'test',
1,
''
),
]);

$cache->method('get')
->with(1)
->willReturn($fileInfo);

$manager->method('getMountsByMountProvider')
->willReturn([$mount1, $mount2]);
$manager->method('getMountFromMountInfo')
->willReturnCallback(function (ICachedMountInfo $mountInfo) use ($mount1, $mount2) {
if ($mountInfo->getMountPoint() === $mount1->getMountPoint()) {
return $mount1;
}
if ($mountInfo->getMountPoint() === $mount2->getMountPoint()) {
return $mount2;
}
return null;
});

$node = new Folder($root, $view, '/bar/foo');
$result = $node->getById(1);
Expand Down
Loading