Skip to content

Commit

Permalink
fix: Use proper path for quota fetching
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr committed Mar 6, 2023
1 parent 3287edd commit d515da5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
8 changes: 7 additions & 1 deletion apps/dav/lib/Connector/Sabre/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,14 @@ public function getQuotaInfo() {
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 {
Expand Down
12 changes: 12 additions & 0 deletions apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ public function testGetQuotaInfoUnlimited(): void {
->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);
Expand All @@ -312,6 +316,10 @@ public function testGetQuotaInfoUnlimited(): void {
->method('getMountPoint')
->willReturn($mountPoint);

$this->view->expects($this->any())
->method('getRelativePath')
->willReturn('/foo');

$mountPoint->method('getMountPoint')
->willReturn('/user/files/mymountpoint');

Expand Down Expand Up @@ -359,6 +367,10 @@ public function testGetQuotaInfoSpecific(): void {
$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
}
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function getRoot() {
* get path relative to the root of the view
*
* @param string $path
* @return string
* @return ?string
*/
public function getRelativePath($path) {
$this->assertPathLength($path);
Expand Down Expand Up @@ -1241,7 +1241,7 @@ private function basicOperation($operation, $path, $hooks = [], $extraParam = nu
* 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()) {
Expand Down
8 changes: 4 additions & 4 deletions lib/private/legacy/OC_Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin
if (!$view) {
throw new \OCP\Files\NotFoundException();
}
$fullPath = $view->getAbsolutePath($path);
$fullPath = Filesystem::normalizePath($view->getAbsolutePath($path));

$cacheKey = $fullPath. '::' . ($includeMountPoints ? 'include' : 'exclude');
if ($useCache) {
Expand Down Expand Up @@ -624,9 +624,9 @@ public static function clearStorageInfo(string $absolutePath): void {
/** @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');
}

/**
Expand Down

0 comments on commit d515da5

Please sign in to comment.