Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: Use proper path for quota fetching
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Mar 6, 2023
commit d515da502f34af151e156ba383c1d2e5c8289520
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