Merge pull request #22657 from nextcloud/bugfix/noid/quota-trash-creation

Check if quota should be applied to path when creating directories
This commit is contained in:
Morris Jobke 2020-09-09 17:37:28 +02:00 committed by GitHub
commit cd563023db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -161,7 +161,7 @@ class Quota extends Wrapper {
$free = $this->free_space($path);
if ($source && $free >= 0 && $mode !== 'r' && $mode !== 'rb') {
// only apply quota for files, not metadata, trash or others
if (strpos(ltrim($path, '/'), 'files/') === 0) {
if ($this->shouldApplyQuota($path)) {
return \OC\Files\Stream\Quota::wrap($source, $free);
}
}
@ -182,6 +182,13 @@ class Quota extends Wrapper {
return ($extension === 'part');
}
/**
* Only apply quota for files, not metadata, trash or others
*/
private function shouldApplyQuota(string $path): bool {
return strpos(ltrim($path, '/'), 'files/') === 0;
}
/**
* @param IStorage $sourceStorage
* @param string $sourceInternalPath
@ -214,7 +221,7 @@ class Quota extends Wrapper {
public function mkdir($path) {
$free = $this->free_space($path);
if ($free === 0.0) {
if ($this->shouldApplyQuota($path) && $free === 0.0) {
return false;
}

View File

@ -211,7 +211,16 @@ class QuotaTest extends \Test\Files\Storage\Storage {
public function testNoMkdirQuotaZero() {
$instance = $this->getLimitedStorage(0.0);
$this->assertFalse($instance->mkdir('foobar'));
$this->assertFalse($instance->mkdir('files'));
$this->assertFalse($instance->mkdir('files/foobar'));
}
public function testMkdirQuotaZeroTrashbin() {
$instance = $this->getLimitedStorage(0.0);
$this->assertTrue($instance->mkdir('files_trashbin'));
$this->assertTrue($instance->mkdir('files_trashbin/files'));
$this->assertTrue($instance->mkdir('files_versions'));
$this->assertTrue($instance->mkdir('cache'));
}
public function testNoTouchQuotaZero() {