]> source.dussan.org Git - nextcloud-server.git/commitdiff
only determine quota_include_external_storage once for quota wrapper 39890/head
authorRobin Appelman <robin@icewind.nl>
Tue, 15 Aug 2023 16:33:57 +0000 (18:33 +0200)
committerRobin Appelman <robin@icewind.nl>
Thu, 7 Sep 2023 14:25:23 +0000 (16:25 +0200)
Signed-off-by: Robin Appelman <robin@icewind.nl>
apps/dav/lib/Connector/Sabre/Directory.php
lib/private/Files/SetupManager.php
lib/private/Files/Storage/Wrapper/Quota.php
tests/lib/Files/ViewTest.php
tests/lib/HelperStorageTest.php

index 4367eabdbef7ba55766fee5a9f47aa8b2f6401bd..49354deb778b60f015d611a106a4a9cedc5cb763 100644 (file)
@@ -325,6 +325,9 @@ class Directory extends \OCA\DAV\Connector\Sabre\Node implements \Sabre\DAV\ICol
         * @return array
         */
        public function getQuotaInfo() {
+               if ($this->quotaInfo) {
+                       return $this->quotaInfo;
+               }
                $relativePath = $this->fileView->getRelativePath($this->info->getPath());
                if ($relativePath === null) {
                        $this->getLogger()->warning("error while getting quota as the relative path cannot be found");
index dfc496524a895de2411cc1bcc028e97bf13b7277..916fcfb0a7e63bff448c59c6e28962d302510e96 100644 (file)
@@ -156,7 +156,8 @@ class SetupManager {
                        return $storage;
                });
 
-               Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) {
+               $quotaIncludeExternal = $this->config->getSystemValue('quota_include_external_storage', false);
+               Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) use ($quotaIncludeExternal) {
                        // set up quota for home storages, even for other users
                        // which can happen when using sharing
 
@@ -168,7 +169,7 @@ class SetupManager {
                                        $user = $storage->getUser();
                                        return new Quota(['storage' => $storage, 'quotaCallback' => function () use ($user) {
                                                return OC_Util::getUserQuota($user);
-                                       }, 'root' => 'files']);
+                                       }, 'root' => 'files', 'include_external_storage' => $quotaIncludeExternal]);
                                }
                        }
 
index cfb2c455a2ce829edb3f2e77c1a09715d280d8b7..b13aa6f9f04e4e33f1b2e8cf01c84f9ed1cf7795 100644 (file)
@@ -45,6 +45,7 @@ class Quota extends Wrapper {
        protected int|float|null $quota;
        protected string $sizeRoot;
        private SystemConfig $config;
+       private bool $quotaIncludeExternalStorage;
 
        /**
         * @param array $parameters
@@ -54,7 +55,7 @@ class Quota extends Wrapper {
                $this->quota = $parameters['quota'] ?? null;
                $this->quotaCallback = $parameters['quotaCallback'] ?? null;
                $this->sizeRoot = $parameters['root'] ?? '';
-               $this->config = \OC::$server->get(SystemConfig::class);
+               $this->quotaIncludeExternalStorage = $parameters['include_external_storage'] ?? false;
        }
 
        /**
@@ -82,7 +83,7 @@ class Quota extends Wrapper {
         * @return int|float
         */
        protected function getSize($path, $storage = null) {
-               if ($this->config->getValue('quota_include_external_storage', false)) {
+               if ($this->quotaIncludeExternalStorage) {
                        $rootInfo = Filesystem::getFileInfo('', 'ext');
                        if ($rootInfo) {
                                return $rootInfo->getSize(true);
index d8c9331fa450b9bbae0d23ea58bfb293d4a4905d..7d1115470329a5638505255593ff99f330bbcc9d 100644 (file)
@@ -23,6 +23,7 @@ use OCP\Files\FileInfo;
 use OCP\Files\GenericFileException;
 use OCP\Files\Mount\IMountManager;
 use OCP\Files\Storage\IStorage;
+use OCP\IDBConnection;
 use OCP\Lock\ILockingProvider;
 use OCP\Lock\LockedException;
 use OCP\Share\IShare;
@@ -1591,7 +1592,7 @@ class ViewTest extends \Test\TestCase {
                                ->getMock();
                        $storage->method('getId')->willReturn('non-null-id');
                        $storage->method('getStorageCache')->willReturnCallback(function () use ($storage) {
-                               return new \OC\Files\Cache\Storage($storage);
+                               return new \OC\Files\Cache\Storage($storage, true, \OC::$server->get(IDBConnection::class));
                        });
 
                        $mounts[] = $this->getMockBuilder(TestMoveableMountPoint::class)
index d3f480502b2d84c36fab3f95094c55cb6ada54cb..0643c4b68a49f19bc9e4f94cd883453c38b24e32 100644 (file)
@@ -10,6 +10,7 @@ namespace Test;
 
 use OC\Files\Storage\Temporary;
 use OCP\Files\Mount\IMountManager;
+use OCP\IConfig;
 use Test\Traits\UserTrait;
 
 /**
@@ -26,12 +27,14 @@ class HelperStorageTest extends \Test\TestCase {
        private $storageMock;
        /** @var \OC\Files\Storage\Storage */
        private $storage;
+       private bool $savedQuotaIncludeExternalStorage;
 
        protected function setUp(): void {
                parent::setUp();
 
                $this->user = $this->getUniqueID('user_');
                $this->createUser($this->user, $this->user);
+               $this->savedQuotaIncludeExternalStorage = $this->getIncludeExternalStorage();
 
                \OC\Files\Filesystem::tearDown();
                \OC_User::setUserId($this->user);
@@ -45,6 +48,7 @@ class HelperStorageTest extends \Test\TestCase {
        }
 
        protected function tearDown(): void {
+               $this->setIncludeExternalStorage($this->savedQuotaIncludeExternalStorage);
                $this->user = null;
 
                if ($this->storageMock) {
@@ -91,6 +95,19 @@ class HelperStorageTest extends \Test\TestCase {
                $this->assertEquals(5, $storageInfo['used']);
                $this->assertEquals(17, $storageInfo['total']);
        }
+       private function getIncludeExternalStorage(): bool {
+               $class = new \ReflectionClass(\OC_Helper::class);
+               $prop = $class->getProperty('quotaIncludeExternalStorage');
+               $prop->setAccessible(true);
+               return $prop->getValue(null) ?? false;
+       }
+
+       private function setIncludeExternalStorage(bool $include) {
+               $class = new \ReflectionClass(\OC_Helper::class);
+               $prop = $class->getProperty('quotaIncludeExternalStorage');
+               $prop->setAccessible(true);
+               $prop->setValue(null, $include);
+       }
 
        /**
         * Test getting the storage info, ignoring extra mount points
@@ -104,8 +121,7 @@ class HelperStorageTest extends \Test\TestCase {
                $extStorage->file_put_contents('extfile.txt', 'abcdefghijklmnopq');
                $extStorage->getScanner()->scan(''); // update root size
 
-               $config = \OC::$server->getConfig();
-               $config->setSystemValue('quota_include_external_storage', false);
+               $this->setIncludeExternalStorage(false);
 
                \OC\Files\Filesystem::mount($extStorage, [], '/' . $this->user . '/files/ext');
 
@@ -129,10 +145,9 @@ class HelperStorageTest extends \Test\TestCase {
 
                \OC\Files\Filesystem::mount($extStorage, [], '/' . $this->user . '/files/ext');
 
-               $config = \OC::$server->getConfig();
-               $oldConfig = $config->getSystemValue('quota_include_external_storage', false);
-               $config->setSystemValue('quota_include_external_storage', 'true');
+               $this->setIncludeExternalStorage(true);
 
+               $config = \OC::$server->get(IConfig::class);
                $config->setUserValue($this->user, 'files', 'quota', '25');
 
                $storageInfo = \OC_Helper::getStorageInfo('');
@@ -140,7 +155,6 @@ class HelperStorageTest extends \Test\TestCase {
                $this->assertEquals(22, $storageInfo['used']);
                $this->assertEquals(25, $storageInfo['total']);
 
-               $config->setSystemValue('quota_include_external_storage', $oldConfig);
                $config->setUserValue($this->user, 'files', 'quota', 'default');
        }
 
@@ -161,15 +175,12 @@ class HelperStorageTest extends \Test\TestCase {
                \OC\Files\Filesystem::mount($extStorage, [], '/' . $this->user . '/files/ext');
 
                $config = \OC::$server->getConfig();
-               $oldConfig = $config->getSystemValue('quota_include_external_storage', false);
-               $config->setSystemValue('quota_include_external_storage', 'true');
+               $this->setIncludeExternalStorage(true);
 
                $storageInfo = \OC_Helper::getStorageInfo('');
                $this->assertEquals(12, $storageInfo['free'], '12 bytes free in home storage');
                $this->assertEquals(22, $storageInfo['used'], '5 bytes of home storage and 17 bytes of the temporary storage are used');
                $this->assertEquals(34, $storageInfo['total'], '5 bytes used and 12 bytes free in home storage as well as 17 bytes used in temporary storage');
-
-               $config->setSystemValue('quota_include_external_storage', $oldConfig);
        }