From d515da502f34af151e156ba383c1d2e5c8289520 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Julius=20H=C3=A4rtl?= Date: Sat, 18 Feb 2023 15:41:01 +0100 Subject: [PATCH] fix: Use proper path for quota fetching MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/dav/lib/Connector/Sabre/Directory.php | 8 +++++++- .../dav/tests/unit/Connector/Sabre/DirectoryTest.php | 12 ++++++++++++ lib/private/Files/View.php | 4 ++-- lib/private/legacy/OC_Helper.php | 8 ++++---- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/apps/dav/lib/Connector/Sabre/Directory.php b/apps/dav/lib/Connector/Sabre/Directory.php index 396cfc3417c..531ccff9d92 100644 --- a/apps/dav/lib/Connector/Sabre/Directory.php +++ b/apps/dav/lib/Connector/Sabre/Directory.php @@ -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 { diff --git a/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php b/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php index edbe4278c3a..a74cb139966 100644 --- a/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php @@ -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 } diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 456f804ee56..1bd131303e3 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -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()) { diff --git a/lib/private/legacy/OC_Helper.php b/lib/private/legacy/OC_Helper.php index 0004edf5b8f..8d708118b96 100644 --- a/lib/private/legacy/OC_Helper.php +++ b/lib/private/legacy/OC_Helper.php @@ -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'); } /** -- 2.39.5