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 \ICachedMountInfo ;
2224use OCP \Files \Config \IUserMountCache ;
2325use OCP \Files \Events \Node \FilesystemTornDownEvent ;
2426use 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