]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix: Use proper path for quota fetching 34835/head
authorJulius Härtl <jus@bitgrid.net>
Sat, 18 Feb 2023 14:41:01 +0000 (15:41 +0100)
committerJulius Härtl (Rebase PR Action) <github@juliushaertl.de>
Mon, 6 Mar 2023 22:46:07 +0000 (22:46 +0000)
Signed-off-by: Julius Härtl <jus@bitgrid.net>
apps/dav/lib/Connector/Sabre/Directory.php
apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
lib/private/Files/View.php
lib/private/legacy/OC_Helper.php

index 396cfc3417c7259e3a7cf5b0dd15f07896b9b89c..531ccff9d9265d80380fdebcb51e09f72751edb9 100644 (file)
@@ -325,8 +325,14 @@ class Directory extends \OCA\DAV\Connector\Sabre\Node implements \Sabre\DAV\ICol
                if ($this->quotaInfo) {
                        return $this->quotaInfo;
                }
+               $relativePath = $this->fileView->getRelativePath($this->info->getPath());
+               if ($relativePath === null) {
+                       $logger->warning("error while getting quota as the relative path cannot be found");
+                       return [0, 0];
+               }
+
                try {
-                       $storageInfo = \OC_Helper::getStorageInfo($this->info->getPath(), $this->info, false);
+                       $storageInfo = \OC_Helper::getStorageInfo($relativePath, $this->info, false);
                        if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) {
                                $free = \OCP\Files\FileInfo::SPACE_UNLIMITED;
                        } else {
index edbe4278c3a4da032c22416341c931f7d2160faa..a74cb139966071a5574e1a4b28b6d4ffeb5362d4 100644 (file)
@@ -304,6 +304,10 @@ class DirectoryTest extends \Test\TestCase {
                        ->method('free_space')
                        ->willReturn(800);
 
+               $this->info->expects($this->any())
+                       ->method('getPath')
+                       ->willReturn('/admin/files/foo');
+
                $this->info->expects($this->once())
                        ->method('getSize')
                        ->willReturn(200);
@@ -312,6 +316,10 @@ class DirectoryTest extends \Test\TestCase {
                        ->method('getMountPoint')
                        ->willReturn($mountPoint);
 
+               $this->view->expects($this->any())
+                       ->method('getRelativePath')
+                       ->willReturn('/foo');
+
                $mountPoint->method('getMountPoint')
                        ->willReturn('/user/files/mymountpoint');
 
@@ -359,6 +367,10 @@ class DirectoryTest extends \Test\TestCase {
                $mountPoint->method('getMountPoint')
                        ->willReturn('/user/files/mymountpoint');
 
+               $this->view->expects($this->any())
+                       ->method('getRelativePath')
+                       ->willReturn('/foo');
+
                $dir = new Directory($this->view, $this->info);
                $this->assertEquals([200, 800], $dir->getQuotaInfo()); //200 used, 800 free
        }
index 456f804ee561772abdbd9dec4b517130ddc7cf92..1bd131303e37e3c31bc82443832010842d70aa71 100644 (file)
@@ -164,7 +164,7 @@ class View {
         * get path relative to the root of the view
         *
         * @param string $path
-        * @return string
+        * @return ?string
         */
        public function getRelativePath($path) {
                $this->assertPathLength($path);
@@ -1241,7 +1241,7 @@ class View {
         * get the path relative to the default root for hook usage
         *
         * @param string $path
-        * @return string
+        * @return ?string
         */
        private function getHookPath($path) {
                if (!Filesystem::getView()) {
index 0004edf5b8f2396ba2f6ed6a8472dae350d58405..8d708118b964bb5835829cbdb869000f61af97de 100644 (file)
@@ -473,7 +473,7 @@ class OC_Helper {
                if (!$view) {
                        throw new \OCP\Files\NotFoundException();
                }
-               $fullPath = $view->getAbsolutePath($path);
+               $fullPath = Filesystem::normalizePath($view->getAbsolutePath($path));
 
                $cacheKey = $fullPath. '::' . ($includeMountPoints ? 'include' : 'exclude');
                if ($useCache) {
@@ -624,9 +624,9 @@ class OC_Helper {
                /** @var ICacheFactory $cacheFactory */
                $cacheFactory = \OC::$server->get(ICacheFactory::class);
                $memcache = $cacheFactory->createLocal('storage_info');
-               $cacheKey = Filesystem::normalizePath($absolutePath) . '::';
-               $memcache->remove($cacheKey . 'include');
-               $memcache->remove($cacheKey . 'exclude');
+               $cacheKeyPrefix = Filesystem::normalizePath($absolutePath) . '::';
+               $memcache->remove($cacheKeyPrefix . 'include');
+               $memcache->remove($cacheKeyPrefix . 'exclude');
        }
 
        /**