Skip to content

Commit c209ba6

Browse files
veryCrunchysalmart-dev
authored andcommitted
fix(files): allow quota write streams with unknown or unlimited space
Assisted-by: Codex:GPT-5 Signed-off-by: veryCrunchy <me@verycrunchy.dev>
1 parent 18dbb9c commit c209ba6

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public function writeStream(string $path, $stream, ?int $size = null): int {
230230
}
231231

232232
if ($size !== null) {
233-
if ($size < $free) {
233+
if ($free < 0 || $size < $free) {
234234
return parent::writeStream($path, $stream, $size);
235235
} else {
236236
throw new NotEnoughSpaceException();

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,26 @@ public function testNoWriteStreamQuota(): void {
251251
$instance->writeStream('files/test.txt', $stream);
252252
}
253253

254+
public function testWriteStreamAllowsUploadPathWithUnlimitedFreeSpace(): void {
255+
$storage = $this->getMockBuilder(Local::class)
256+
->onlyMethods(['free_space'])
257+
->setConstructorArgs([['datadir' => $this->tmpDir]])
258+
->getMock();
259+
$storage->expects($this->any())
260+
->method('free_space')
261+
->willReturn(Files\FileInfo::SPACE_UNLIMITED);
262+
$storage->mkdir('uploads');
263+
264+
$instance = new Quota(['storage' => $storage, 'quota' => 5.0]);
265+
266+
$stream = fopen('php://temp', 'w+');
267+
fwrite($stream, 'foobar');
268+
rewind($stream);
269+
270+
$this->assertEquals(6, $instance->writeStream('uploads/chunk', $stream, 6));
271+
$this->assertEquals('foobar', $instance->file_get_contents('uploads/chunk'));
272+
}
273+
254274
public function testNoWriteStreamQuotaZero(): void {
255275
$instance = $this->getLimitedStorage(0.0);
256276
$stream = fopen('php://temp', 'w+');

0 commit comments

Comments
 (0)