diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-05-28 18:31:20 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-05-28 18:31:20 +0200 |
commit | e114d002421d5cf560ddc277bbd1604c4b70f03b (patch) | |
tree | 472200a1fd36e79095e495025a071296470ee180 | |
parent | 173b14730556d1b32d06e6b362c65b4a6dabb178 (diff) | |
download | nextcloud-server-e114d002421d5cf560ddc277bbd1604c4b70f03b.tar.gz nextcloud-server-e114d002421d5cf560ddc277bbd1604c4b70f03b.zip |
Only use quota stream wrapper on "files"
Prevent using the quota stream wrapper on trashbin folders and other
metadata folders
-rw-r--r-- | lib/private/files/storage/wrapper/quota.php | 8 | ||||
-rw-r--r-- | tests/lib/files/storage/wrapper/quota.php | 34 |
2 files changed, 28 insertions, 14 deletions
diff --git a/lib/private/files/storage/wrapper/quota.php b/lib/private/files/storage/wrapper/quota.php index 92d749a814f..98664e27e2d 100644 --- a/lib/private/files/storage/wrapper/quota.php +++ b/lib/private/files/storage/wrapper/quota.php @@ -141,10 +141,12 @@ class Quota extends Wrapper { $source = $this->storage->fopen($path, $mode); $free = $this->free_space(''); if ($source && $free >= 0 && $mode !== 'r' && $mode !== 'rb') { - return \OC\Files\Stream\Quota::wrap($source, $free); - } else { - return $source; + // only apply quota for files, not metadata, trash or others + if (strpos(ltrim($path, '/'), 'files/') === 0) { + return \OC\Files\Stream\Quota::wrap($source, $free); + } } + return $source; } /** diff --git a/tests/lib/files/storage/wrapper/quota.php b/tests/lib/files/storage/wrapper/quota.php index a5828296be9..441f3a39d32 100644 --- a/tests/lib/files/storage/wrapper/quota.php +++ b/tests/lib/files/storage/wrapper/quota.php @@ -35,20 +35,21 @@ class Quota extends \Test\Files\Storage\Storage { */ protected function getLimitedStorage($limit) { $storage = new \OC\Files\Storage\Local(array('datadir' => $this->tmpDir)); + $storage->mkdir('files'); $storage->getScanner()->scan(''); return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $limit)); } public function testFilePutContentsNotEnoughSpace() { $instance = $this->getLimitedStorage(3); - $this->assertFalse($instance->file_put_contents('foo', 'foobar')); + $this->assertFalse($instance->file_put_contents('files/foo', 'foobar')); } public function testCopyNotEnoughSpace() { $instance = $this->getLimitedStorage(9); - $this->assertEquals(6, $instance->file_put_contents('foo', 'foobar')); + $this->assertEquals(6, $instance->file_put_contents('files/foo', 'foobar')); $instance->getScanner()->scan(''); - $this->assertFalse($instance->copy('foo', 'bar')); + $this->assertFalse($instance->copy('files/foo', 'files/bar')); } public function testFreeSpace() { @@ -92,17 +93,17 @@ class Quota extends \Test\Files\Storage\Storage { public function testFWriteNotEnoughSpace() { $instance = $this->getLimitedStorage(9); - $stream = $instance->fopen('foo', 'w+'); + $stream = $instance->fopen('files/foo', 'w+'); $this->assertEquals(6, fwrite($stream, 'foobar')); $this->assertEquals(3, fwrite($stream, 'qwerty')); fclose($stream); - $this->assertEquals('foobarqwe', $instance->file_get_contents('foo')); + $this->assertEquals('foobarqwe', $instance->file_get_contents('files/foo')); } public function testStreamCopyWithEnoughSpace() { $instance = $this->getLimitedStorage(16); $inputStream = fopen('data://text/plain,foobarqwerty', 'r'); - $outputStream = $instance->fopen('foo', 'w+'); + $outputStream = $instance->fopen('files/foo', 'w+'); list($count, $result) = \OC_Helper::streamCopy($inputStream, $outputStream); $this->assertEquals(12, $count); $this->assertTrue($result); @@ -113,7 +114,7 @@ class Quota extends \Test\Files\Storage\Storage { public function testStreamCopyNotEnoughSpace() { $instance = $this->getLimitedStorage(9); $inputStream = fopen('data://text/plain,foobarqwerty', 'r'); - $outputStream = $instance->fopen('foo', 'w+'); + $outputStream = $instance->fopen('files/foo', 'w+'); list($count, $result) = \OC_Helper::streamCopy($inputStream, $outputStream); $this->assertEquals(9, $count); $this->assertFalse($result); @@ -139,16 +140,27 @@ class Quota extends \Test\Files\Storage\Storage { $instance = $this->getLimitedStorage(9); // create test file first - $stream = $instance->fopen('foo', 'w+'); + $stream = $instance->fopen('files/foo', 'w+'); fwrite($stream, 'blablacontent'); fclose($stream); - $stream = $instance->fopen('foo', 'r'); + $stream = $instance->fopen('files/foo', 'r'); $meta = stream_get_meta_data($stream); $this->assertEquals('plainfile', $meta['wrapper_type']); fclose($stream); - $stream = $instance->fopen('foo', 'rb'); + $stream = $instance->fopen('files/foo', 'rb'); + $meta = stream_get_meta_data($stream); + $this->assertEquals('plainfile', $meta['wrapper_type']); + fclose($stream); + } + + public function testReturnRegularStreamWhenOutsideFiles() { + $instance = $this->getLimitedStorage(9); + $instance->mkdir('files_other'); + + // create test file first + $stream = $instance->fopen('files_other/foo', 'w+'); $meta = stream_get_meta_data($stream); $this->assertEquals('plainfile', $meta['wrapper_type']); fclose($stream); @@ -156,7 +168,7 @@ class Quota extends \Test\Files\Storage\Storage { public function testReturnQuotaStreamOnWrite() { $instance = $this->getLimitedStorage(9); - $stream = $instance->fopen('foo', 'w+'); + $stream = $instance->fopen('files/foo', 'w+'); $meta = stream_get_meta_data($stream); $expected_type = defined('HHVM_VERSION') ? 'File' : 'user-space'; $this->assertEquals($expected_type, $meta['wrapper_type']); |