From 87e5fd0d2c46c1a97050309d37864d0acb5aa8d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 8 Sep 2020 07:33:54 +0200 Subject: [PATCH 1/3] Check if quota should be applied to path when creating directories MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes an issue where the files_trashbin hierarchy of a user could not been created as the mkdir operations were blocked by the quota storage wrapper. Even with 0 quota, users should be able to have a trashbin for external storages. Signed-off-by: Julius Härtl --- lib/private/Files/Storage/Wrapper/Quota.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/private/Files/Storage/Wrapper/Quota.php b/lib/private/Files/Storage/Wrapper/Quota.php index 62d3335987c..4b99af46b02 100644 --- a/lib/private/Files/Storage/Wrapper/Quota.php +++ b/lib/private/Files/Storage/Wrapper/Quota.php @@ -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; } From 74747163d642e6be8d26700447357699ee673d05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 8 Sep 2020 11:35:32 +0200 Subject: [PATCH 2/3] Make sure tests cover the new mkdir behaviour on 0 quota MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- tests/lib/Files/Storage/Wrapper/QuotaTest.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/lib/Files/Storage/Wrapper/QuotaTest.php b/tests/lib/Files/Storage/Wrapper/QuotaTest.php index 65cfe30eb1c..651ee975ab2 100644 --- a/tests/lib/Files/Storage/Wrapper/QuotaTest.php +++ b/tests/lib/Files/Storage/Wrapper/QuotaTest.php @@ -211,7 +211,17 @@ 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() { From e6fca0a519397ef140947fca2d730535fa9b4070 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Wed, 9 Sep 2020 17:36:58 +0200 Subject: [PATCH 3/3] Fix code style Signed-off-by: Morris Jobke --- tests/lib/Files/Storage/Wrapper/QuotaTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/lib/Files/Storage/Wrapper/QuotaTest.php b/tests/lib/Files/Storage/Wrapper/QuotaTest.php index 651ee975ab2..199ba5f2e26 100644 --- a/tests/lib/Files/Storage/Wrapper/QuotaTest.php +++ b/tests/lib/Files/Storage/Wrapper/QuotaTest.php @@ -221,7 +221,6 @@ class QuotaTest extends \Test\Files\Storage\Storage { $this->assertTrue($instance->mkdir('files_trashbin/files')); $this->assertTrue($instance->mkdir('files_versions')); $this->assertTrue($instance->mkdir('cache')); - } public function testNoTouchQuotaZero() {