55 * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
66 * SPDX-License-Identifier: AGPL-3.0-only
77 */
8+
89namespace OC \Files \Node ;
910
1011use OC \Files \FileInfo ;
1920use OCP \Cache \CappedMemoryCache ;
2021use OCP \EventDispatcher \IEventDispatcher ;
2122use OCP \Files \Cache \ICacheEntry ;
23+ use OCP \Files \Config \ICachedMountFileInfo ;
24+ use OCP \Files \Config \ICachedMountInfo ;
2225use OCP \Files \Config \IUserMountCache ;
2326use OCP \Files \Events \Node \FilesystemTornDownEvent ;
2427use OCP \Files \IRootFolder ;
@@ -82,10 +85,8 @@ public function __construct(
8285
8386 /**
8487 * Get the user for which the filesystem is setup
85- *
86- * @return \OC\User\User
8788 */
88- public function getUser () {
89+ public function getUser (): ? IUser {
8990 return $ this ->user ;
9091 }
9192
@@ -411,12 +412,12 @@ public function getByIdInPath(int $id, string $path): array {
411412 } else {
412413 $ user = null ;
413414 }
414- $ mountsContainingFile = $ mountCache ->getMountsForFileId ($ id , $ user );
415+ $ mountInfosContainingFiles = $ mountCache ->getMountsForFileId ($ id , $ user );
415416
416417 // if the mount isn't in the cache yet, perform a setup first, then try again
417- if (count ($ mountsContainingFile ) === 0 ) {
418+ if (count ($ mountInfosContainingFiles ) === 0 ) {
418419 $ setupManager ->setupForPath ($ path , true );
419- $ mountsContainingFile = $ mountCache ->getMountsForFileId ($ id , $ user );
420+ $ mountInfosContainingFiles = $ mountCache ->getMountsForFileId ($ id , $ user );
420421 }
421422
422423 // when a user has access through the same storage through multiple paths
@@ -428,16 +429,31 @@ public function getByIdInPath(int $id, string $path): array {
428429
429430 $ mountRootIds = array_map (function ($ mount ) {
430431 return $ mount ->getRootId ();
431- }, $ mountsContainingFile );
432+ }, $ mountInfosContainingFiles );
432433 $ mountRootPaths = array_map (function ($ mount ) {
433434 return $ mount ->getRootInternalPath ();
434- }, $ mountsContainingFile );
435+ }, $ mountInfosContainingFiles );
435436 $ mountProviders = array_unique (array_map (function ($ mount ) {
436437 return $ mount ->getMountProvider ();
437- }, $ mountsContainingFile ));
438+ }, $ mountInfosContainingFiles ));
439+ $ mountPoints = array_map (fn (ICachedMountInfo $ mountInfo ) => $ mountInfo ->getMountPoint (), $ mountInfosContainingFiles );
438440 $ mountRoots = array_combine ($ mountRootIds , $ mountRootPaths );
439441
440- $ mountsContainingFile = array_filter (array_map ($ this ->mountManager ->getMountFromMountInfo (...), $ mountsContainingFile ));
442+ $ mounts = $ this ->mountManager ->getMountsByMountProvider ($ path , $ mountProviders );
443+ $ mountsContainingFile = array_filter ($ mounts , fn (IMountPoint $ mount ) => in_array ($ mount ->getMountPoint (), $ mountPoints ));
444+
445+ if (count ($ mountsContainingFile ) == 0 && count ($ mountInfosContainingFiles ) > 0 ) {
446+ if (!$ user ) {
447+ $ user = $ this ->getUser ()?->getUID();
448+ }
449+ if (!$ user ) {
450+ /** @var ICachedMountFileInfo $firstMount */
451+ $ firstMount = current ($ mountInfosContainingFiles );
452+ $ user = $ firstMount ->getUser ()->getUID ();
453+ }
454+ $ mountInfosContainingFiles = array_filter ($ mountInfosContainingFiles , fn (ICachedMountInfo $ mountInfo ) => $ mountInfo ->getUser ()->getUID () === $ user );
455+ $ mountsContainingFile = array_filter (array_map ($ this ->mountManager ->getMountFromMountInfo (...), $ mountInfosContainingFiles ));
456+ }
441457
442458 if (count ($ mountsContainingFile ) === 0 ) {
443459 if ($ user === $ this ->getAppDataDirectoryName ()) {
0 commit comments