diff --git a/lib/private/Files/Storage/Wrapper/Quota.php b/lib/private/Files/Storage/Wrapper/Quota.php index b0ff0117b960f..a7fd91b1f4c6a 100644 --- a/lib/private/Files/Storage/Wrapper/Quota.php +++ b/lib/private/Files/Storage/Wrapper/Quota.php @@ -230,7 +230,7 @@ public function writeStream(string $path, $stream, ?int $size = null): int { } if ($size !== null) { - if ($size < $free) { + if ($free < 0 || $size < $free) { return parent::writeStream($path, $stream, $size); } else { throw new NotEnoughSpaceException(); diff --git a/tests/lib/Files/Storage/Wrapper/QuotaTest.php b/tests/lib/Files/Storage/Wrapper/QuotaTest.php index 150917b9dd9e9..9c317d6d815fc 100644 --- a/tests/lib/Files/Storage/Wrapper/QuotaTest.php +++ b/tests/lib/Files/Storage/Wrapper/QuotaTest.php @@ -251,6 +251,26 @@ public function testNoWriteStreamQuota(): void { $instance->writeStream('files/test.txt', $stream); } + public function testWriteStreamAllowsUploadPathWithUnlimitedFreeSpace(): void { + $storage = $this->getMockBuilder(Local::class) + ->onlyMethods(['free_space']) + ->setConstructorArgs([['datadir' => $this->tmpDir]]) + ->getMock(); + $storage->expects($this->any()) + ->method('free_space') + ->willReturn(Files\FileInfo::SPACE_UNLIMITED); + $storage->mkdir('uploads'); + + $instance = new Quota(['storage' => $storage, 'quota' => 5.0]); + + $stream = fopen('php://temp', 'w+'); + fwrite($stream, 'foobar'); + rewind($stream); + + $this->assertEquals(6, $instance->writeStream('uploads/chunk', $stream, 6)); + $this->assertEquals('foobar', $instance->file_get_contents('uploads/chunk')); + } + public function testNoWriteStreamQuotaZero(): void { $instance = $this->getLimitedStorage(0.0); $stream = fopen('php://temp', 'w+');