55 * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
66 * SPDX-License-Identifier: AGPL-3.0-only
77 */
8+
89namespace OC \Files \Config ;
910
1011use OC \User \LazyUser ;
@@ -32,11 +33,13 @@ class UserMountCache implements IUserMountCache {
3233
3334 /**
3435 * Cached mount info.
36+ *
3537 * @var CappedMemoryCache<ICachedMountInfo[]>
3638 **/
3739 private CappedMemoryCache $ mountsForUsers ;
3840 /**
3941 * fileid => internal path mapping for cached mount info.
42+ *
4043 * @var CappedMemoryCache<string>
4144 **/
4245 private CappedMemoryCache $ internalPathCache ;
@@ -72,7 +75,9 @@ public function registerMounts(IUser $user, array $mounts, ?array $mountProvider
7275
7376 $ cachedMounts = $ this ->getMountsForUser ($ user );
7477 if (is_array ($ mountProviderClasses )) {
75- $ cachedMounts = array_filter ($ cachedMounts , function (ICachedMountInfo $ mountInfo ) use ($ mountProviderClasses , $ newMounts ) {
78+ $ cachedMounts = array_filter ($ cachedMounts , function (
79+ ICachedMountInfo $ mountInfo ,
80+ ) use ($ mountProviderClasses , $ newMounts ) {
7681 // for existing mounts that didn't have a mount provider set
7782 // we still want the ones that map to new mounts
7883 if ($ mountInfo ->getMountProvider () === '' && isset ($ newMounts [$ mountInfo ->getKey ()])) {
@@ -535,7 +540,13 @@ public function removeMount(string $mountPoint, ?IUser $user = null): void {
535540 }
536541 }
537542
538- public function addMount (IUser $ user , string $ mountPoint , ICacheEntry $ rootCacheEntry , string $ mountProvider , ?int $ mountId = null ): void {
543+ public function addMount (
544+ IUser $ user ,
545+ string $ mountPoint ,
546+ ICacheEntry $ rootCacheEntry ,
547+ string $ mountProvider ,
548+ ?int $ mountId = null ,
549+ ): void {
539550 $ this ->connection ->insertIgnoreConflict ('mounts ' , [
540551 'storage_id ' => $ rootCacheEntry ->getStorageId (),
541552 'root_id ' => $ rootCacheEntry ->getId (),
@@ -556,4 +567,21 @@ public function flush(): void {
556567 $ this ->internalPathCache = new CappedMemoryCache ();
557568 $ this ->mountsForUsers = new CappedMemoryCache ();
558569 }
570+
571+ public function getMountAtPath (IUser $ user , string $ mountPoint ): ?ICachedMountInfo {
572+ if (isset ($ this ->mountsForUsers [$ user ->getUID ()])) {
573+ return $ this ->mountsForUsers [$ user ->getUID ()][$ mountPoint ] ?? null ;
574+ }
575+
576+ $ builder = $ this ->connection ->getQueryBuilder ();
577+ $ query = $ builder ->select ('storage_id ' , 'root_id ' , 'user_id ' , 'mount_point ' , 'mount_id ' , 'f.path ' , 'mount_provider_class ' )
578+ ->from ('mounts ' , 'm ' )
579+ ->innerJoin ('m ' , 'filecache ' , 'f ' , $ builder ->expr ()->eq ('m.root_id ' , 'f.fileid ' ))
580+ ->where ($ builder ->expr ()->eq ('user_id ' , $ builder ->createNamedParameter ($ user ->getUID ())))
581+ ->andWhere ($ builder ->expr ()->eq ('mount_point ' , $ builder ->createNamedParameter ($ mountPoint )))
582+ ->setMaxResults (1 );
583+
584+ $ row = $ query ->executeQuery ()->fetch ();
585+ return $ row ? $ this ->dbRowToMountInfo ($ row ) : null ;
586+ }
559587}
0 commit comments