Skip to content

Commit f68894f

Browse files
committed
fix: getById: don't setup for all users with access by default
Signed-off-by: Robin Appelman <[email protected]>
1 parent ebe0600 commit f68894f

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

lib/private/Files/Mount/Manager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ public function getSetupManager(): SetupManager {
230230
}
231231

232232
/**
233-
* Return all mounts in a path from a specific mount provider
233+
* Return all mounts in a path from a specific mount provider, indexed by mount point
234234
*
235235
* @param string $path
236236
* @param string[] $mountProviders
237-
* @return IMountPoint[]
237+
* @return array<string, IMountPoint>
238238
*/
239239
public function getMountsByMountProvider(string $path, array $mountProviders) {
240240
$this->getSetupManager()->setupForProvider($path, $mountProviders);

lib/private/Files/Node/Root.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
66
* SPDX-License-Identifier: AGPL-3.0-only
77
*/
8+
89
namespace OC\Files\Node;
910

1011
use OC\Files\FileInfo;
@@ -19,6 +20,7 @@
1920
use OCP\Cache\CappedMemoryCache;
2021
use OCP\EventDispatcher\IEventDispatcher;
2122
use OCP\Files\Cache\ICacheEntry;
23+
use OCP\Files\Config\ICachedMountInfo;
2224
use OCP\Files\Config\IUserMountCache;
2325
use OCP\Files\Events\Node\FilesystemTornDownEvent;
2426
use OCP\Files\IRootFolder;
@@ -411,12 +413,12 @@ public function getByIdInPath(int $id, string $path): array {
411413
} else {
412414
$user = null;
413415
}
414-
$mountsContainingFile = $mountCache->getMountsForFileId($id, $user);
416+
$mountInfosContainingFiles = $mountCache->getMountsForFileId($id, $user);
415417

416418
// if the mount isn't in the cache yet, perform a setup first, then try again
417-
if (count($mountsContainingFile) === 0) {
419+
if (count($mountInfosContainingFiles) === 0) {
418420
$setupManager->setupForPath($path, true);
419-
$mountsContainingFile = $mountCache->getMountsForFileId($id, $user);
421+
$mountInfosContainingFiles = $mountCache->getMountsForFileId($id, $user);
420422
}
421423

422424
// when a user has access through the same storage through multiple paths
@@ -428,16 +430,28 @@ public function getByIdInPath(int $id, string $path): array {
428430

429431
$mountRootIds = array_map(function ($mount) {
430432
return $mount->getRootId();
431-
}, $mountsContainingFile);
433+
}, $mountInfosContainingFiles);
432434
$mountRootPaths = array_map(function ($mount) {
433435
return $mount->getRootInternalPath();
434-
}, $mountsContainingFile);
436+
}, $mountInfosContainingFiles);
435437
$mountProviders = array_unique(array_map(function ($mount) {
436438
return $mount->getMountProvider();
437-
}, $mountsContainingFile));
439+
}, $mountInfosContainingFiles));
440+
$mountPoints = array_map(fn (ICachedMountInfo $mountInfo) => $mountInfo->getMountPoint(), $mountInfosContainingFiles);
438441
$mountRoots = array_combine($mountRootIds, $mountRootPaths);
439442

440-
$mountsContainingFile = array_filter(array_map($this->mountManager->getMountFromMountInfo(...), $mountsContainingFile));
443+
$mounts = $this->mountManager->getMountsByMountProvider($path, $mountProviders);
444+
$mountsContainingFile = array_filter($mounts, fn (IMountPoint $mount) => in_array($mount->getMountPoint(), $mountPoints));
445+
446+
if (count($mountsContainingFile) == 0) {
447+
if (!$user) {
448+
$user = $this->getUser()->getUID();
449+
}
450+
if ($user) {
451+
$mountInfosContainingFiles = array_filter($mountInfosContainingFiles, fn (ICachedMountInfo $mountInfo) => $mountInfo->getUser()->getUID() === $user);
452+
}
453+
$mountsContainingFile = array_filter(array_map($this->mountManager->getMountFromMountInfo(...), $mountInfosContainingFiles));
454+
}
441455

442456
if (count($mountsContainingFile) === 0) {
443457
if ($user === $this->getAppDataDirectoryName()) {

0 commit comments

Comments
 (0)