]> source.dussan.org Git - nextcloud-server.git/commitdiff
allow getting cached mounts by path from the mount cache
authorRobin Appelman <robin@icewind.nl>
Tue, 8 Mar 2022 16:11:41 +0000 (17:11 +0100)
committerRobin Appelman <robin@icewind.nl>
Thu, 24 Mar 2022 16:01:12 +0000 (17:01 +0100)
Signed-off-by: Robin Appelman <robin@icewind.nl>
lib/private/Files/Config/UserMountCache.php
lib/public/Files/Config/IUserMountCache.php

index dc2640361e71db2d660b51983910dfa9dd72481d..e5c2baa273547435a2225d79f9282c05cfa412cc 100644 (file)
@@ -446,4 +446,37 @@ class UserMountCache implements IUserMountCache {
                $this->cacheInfoCache = new CappedMemoryCache();
                $this->mountsForUsers = new CappedMemoryCache();
        }
+
+       public function getMountForPath(IUser $user, string $path): ICachedMountInfo {
+               $mounts = $this->getMountsForUser($user);
+               $mountPoints = array_map(function (ICachedMountInfo $mount) {
+                       return $mount->getMountPoint();
+               }, $mounts);
+               $mounts = array_combine($mountPoints, $mounts);
+
+               $current = $path;
+               while (true) {
+                       $mountPoint = $current . '/';
+                       if (isset($mounts[$mountPoint])) {
+                               return $mounts[$mountPoint];
+                       } elseif ($current === '') {
+                               break;
+                       }
+
+                       $current = dirname($current);
+                       if ($current === '.' || $current === '/') {
+                               $current = '';
+                       }
+               }
+
+               throw new NotFoundException("No cached mount for path " . $path);
+       }
+
+       public function getMountsInForPath(IUser $user, string $path): array {
+               $path = rtrim($path, '/') . '/';
+               $mounts = $this->getMountsForUser($user);
+               return array_filter($mounts, function (ICachedMountInfo $mount) use ($path) {
+                       return $mount->getMountPoint() !== $path && strpos($mount->getMountPoint(), $path) === 0;
+               });
+       }
 }
index 08f95990d3cafd92355dfab002e330dfa5fb3d60..e45bea9b5d9734a3517d703998980d3fd7154d46 100644 (file)
@@ -25,6 +25,7 @@
 namespace OCP\Files\Config;
 
 use OCP\Files\Mount\IMountPoint;
+use OCP\Files\NotFoundException;
 use OCP\IUser;
 
 /**
@@ -125,4 +126,26 @@ interface IUserMountCache {
         * @since 20.0.0
         */
        public function clear(): void;
+
+       /**
+        * Get all cached mounts for a user
+        *
+        * @param IUser $user
+        * @param string $path
+        * @return ICachedMountInfo
+        * @throws NotFoundException
+        * @since 24.0.0
+        */
+       public function getMountForPath(IUser $user, string $path): ICachedMountInfo;
+
+       /**
+        * Get all cached mounts for a user inside a path
+        *
+        * @param IUser $user
+        * @param string $path
+        * @return ICachedMountInfo[]
+        * @throws NotFoundException
+        * @since 24.0.0
+        */
+       public function getMountsInForPath(IUser $user, string $path): array;
 }