Skip to content

Commit cd56302

Browse files
authored
Merge pull request #22657 from nextcloud/bugfix/noid/quota-trash-creation
Check if quota should be applied to path when creating directories
2 parents 22ff60e + e6fca0a commit cd56302

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

lib/private/Files/Storage/Wrapper/Quota.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function fopen($path, $mode) {
161161
$free = $this->free_space($path);
162162
if ($source && $free >= 0 && $mode !== 'r' && $mode !== 'rb') {
163163
// only apply quota for files, not metadata, trash or others
164-
if (strpos(ltrim($path, '/'), 'files/') === 0) {
164+
if ($this->shouldApplyQuota($path)) {
165165
return \OC\Files\Stream\Quota::wrap($source, $free);
166166
}
167167
}
@@ -182,6 +182,13 @@ private function isPartFile($path) {
182182
return ($extension === 'part');
183183
}
184184

185+
/**
186+
* Only apply quota for files, not metadata, trash or others
187+
*/
188+
private function shouldApplyQuota(string $path): bool {
189+
return strpos(ltrim($path, '/'), 'files/') === 0;
190+
}
191+
185192
/**
186193
* @param IStorage $sourceStorage
187194
* @param string $sourceInternalPath
@@ -214,7 +221,7 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
214221

215222
public function mkdir($path) {
216223
$free = $this->free_space($path);
217-
if ($free === 0.0) {
224+
if ($this->shouldApplyQuota($path) && $free === 0.0) {
218225
return false;
219226
}
220227

tests/lib/Files/Storage/Wrapper/QuotaTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,16 @@ public function testInstanceOfStorageWrapper() {
211211

212212
public function testNoMkdirQuotaZero() {
213213
$instance = $this->getLimitedStorage(0.0);
214-
$this->assertFalse($instance->mkdir('foobar'));
214+
$this->assertFalse($instance->mkdir('files'));
215+
$this->assertFalse($instance->mkdir('files/foobar'));
216+
}
217+
218+
public function testMkdirQuotaZeroTrashbin() {
219+
$instance = $this->getLimitedStorage(0.0);
220+
$this->assertTrue($instance->mkdir('files_trashbin'));
221+
$this->assertTrue($instance->mkdir('files_trashbin/files'));
222+
$this->assertTrue($instance->mkdir('files_versions'));
223+
$this->assertTrue($instance->mkdir('cache'));
215224
}
216225

217226
public function testNoTouchQuotaZero() {

0 commit comments

Comments
 (0)