]> source.dussan.org Git - nextcloud-server.git/commitdiff
optimize isShared and isMounted 41119/head
authorRobin Appelman <robin@icewind.nl>
Mon, 23 Oct 2023 11:22:23 +0000 (13:22 +0200)
committerRobin Appelman <robin@icewind.nl>
Wed, 8 Nov 2023 16:34:58 +0000 (17:34 +0100)
Signed-off-by: Robin Appelman <robin@icewind.nl>
lib/private/Files/FileInfo.php
tests/lib/Files/FileInfoTest.php

index da0ae7e8d899e58167c8304cf1f6240eacf375b7..4ef32861f244af571f45fdfee4846f9ac2ac1e4e 100644 (file)
  */
 namespace OC\Files;
 
-use OCA\Files_Sharing\ISharedStorage;
+use OC\Files\Mount\HomeMountPoint;
+use OCA\Files_Sharing\External\Mount;
+use OCA\Files_Sharing\ISharedMountPoint;
 use OCP\Files\Cache\ICacheEntry;
-use OCP\Files\IHomeStorage;
 use OCP\Files\Mount\IMountPoint;
 use OCP\IUser;
 
@@ -312,13 +313,12 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
         * @return bool
         */
        public function isShared() {
-               $storage = $this->getStorage();
-               return $storage->instanceOfStorage(ISharedStorage::class);
+               return $this->mount instanceof ISharedMountPoint;
        }
 
        public function isMounted() {
-               $storage = $this->getStorage();
-               return !($storage->instanceOfStorage(IHomeStorage::class) || $storage->instanceOfStorage(ISharedStorage::class));
+               $isHome = $this->mount instanceof HomeMountPoint;
+               return !$isHome && !$this->isShared();
        }
 
        /**
index fd2b506beb9cb274d3a716ea944847e3635a5697..98f51aed67db596ec02848511b03cd288c8229c7 100644 (file)
@@ -9,6 +9,8 @@
 namespace Test\Files;
 
 use OC\Files\FileInfo;
+use OC\Files\Mount\HomeMountPoint;
+use OC\Files\Mount\MountPoint;
 use OC\Files\Storage\Home;
 use OC\Files\Storage\Temporary;
 use OCP\IConfig;
@@ -33,19 +35,27 @@ class FileInfoTest extends TestCase {
                        ->willReturn('foo');
                $user->method('getHome')
                        ->willReturn('foo');
+               $storage = new Home(['user' => $user]);
 
                $fileInfo = new FileInfo(
                        '',
-                       new Home(['user' => $user]),
-                       '', [], null);
+                       $storage,
+                       '',
+                       [],
+                       new HomeMountPoint($user, $storage, '/foo/files')
+               );
                $this->assertFalse($fileInfo->isMounted());
        }
 
        public function testIsMountedNonHomeStorage() {
+               $storage = new Temporary();
                $fileInfo = new FileInfo(
                        '',
-                       new Temporary(),
-                       '', [], null);
+                       $storage,
+                       '',
+                       [],
+                       new MountPoint($storage, '/foo/files/bar')
+               );
                $this->assertTrue($fileInfo->isMounted());
        }
 }