Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 6 additions & 2 deletions lib/private/Files/Storage/Wrapper/Quota.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ public function copy(string $source, string $target): bool {

#[\Override]
public function fopen(string $path, string $mode) {
if (!$this->hasQuota() || $this->isPartFile($path)) {
// reading doesn't consume quota, so it should not be restricted by it
$isReadMode = $mode === 'r' || $mode === 'rb';
if ($isReadMode || !$this->hasQuota() || $this->isPartFile($path)) {
return $this->getWrapperStorage()->fopen($path, $mode);
}

Expand All @@ -134,7 +136,9 @@ public function fopen(string $path, string $mode) {
}

$source = $this->getWrapperStorage()->fopen($path, $mode);
if ($source && (is_int($free) || is_float($free)) && $free >= 0 && $mode !== 'r' && $mode !== 'rb') {
// writing past the remaining free space fails. Negative values mean the free
// space is unknown or unlimited (FileInfo::SPACE_*), so no limit is applied
if ($source && (is_int($free) || is_float($free)) && $free >= 0) {
Comment thread
cristianscheid marked this conversation as resolved.
// only apply quota for files, not metadata, trash or others
if ($this->shouldApplyQuota($path)) {
return \OC\Files\Stream\Quota::wrap($source, $free);
Expand Down
20 changes: 20 additions & 0 deletions tests/lib/Files/Storage/Wrapper/QuotaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,26 @@ public function testReturnRegularStreamOnRead(): void {
fclose($stream);
}

public function testFopenReadWhenQuotaExceeded(): void {
$instance = $this->getLimitedStorage(3);

// write foobar (6 bytes) past the quota wrapper and scan it,
// so the cached usage exceeds the 3 bytes quota
$instance->getWrapperStorage()->file_put_contents('files/foo', 'foobar');
$instance->getWrapperStorage()->getScanner()->scan('');
$this->assertEquals(0, $instance->free_space('files'));

foreach (['r', 'rb'] as $mode) {
$stream = $instance->fopen('files/foo', $mode);
$this->assertIsResource($stream);
$this->assertEquals('foobar', stream_get_contents($stream));
fclose($stream);
}

$this->assertFalse($instance->fopen('files/foo', 'w'));
$this->assertFalse($instance->fopen('files/foo', 'r+'));
}

public function testReturnRegularStreamWhenOutsideFiles(): void {
$instance = $this->getLimitedStorage(9);
$instance->mkdir('files_other');
Expand Down
Loading