]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fixed quota stream to not wrap read-only fopen calls
authorVincent Petry <pvince81@owncloud.com>
Fri, 25 Oct 2013 10:33:16 +0000 (12:33 +0200)
committerVincent Petry <pvince81@owncloud.com>
Fri, 25 Oct 2013 10:33:16 +0000 (12:33 +0200)
lib/private/files/storage/wrapper/quota.php
tests/lib/files/storage/wrapper/quota.php

index e2da8cf2e05a396ca1376fcbb56031fa0e72e617..43016e0892fbab9572a26fd2bdc14d8610746d31 100644 (file)
@@ -95,7 +95,7 @@ class Quota extends Wrapper {
        public function fopen($path, $mode) {
                $source = $this->storage->fopen($path, $mode);
                $free = $this->free_space('');
-               if ($free >= 0) {
+               if ($free >= 0 && $mode !== 'r') {
                        return \OC\Files\Stream\Quota::wrap($source, $free);
                } else {
                        return $source;
index 3702f8154f55fafe171bb78457d20a4e4e1269e9..9b14335782faa2d378a9fc96d5b5fe6caa978b2a 100644 (file)
@@ -58,4 +58,26 @@ class Quota extends \Test\Files\Storage\Storage {
                fclose($stream);
                $this->assertEquals('foobarqwe', $instance->file_get_contents('foo'));
        }
+
+       public function testReturnRegularStreamOnRead(){
+               $instance = $this->getLimitedStorage(9);
+
+               // create test file first
+               $stream = $instance->fopen('foo', 'w+');
+               fwrite($stream, 'blablacontent');
+               fclose($stream);
+
+               $stream = $instance->fopen('foo', 'r');
+               $meta = stream_get_meta_data($stream);
+               $this->assertEquals('plainfile', $meta['wrapper_type']);
+               fclose($stream);
+       }
+
+       public function testReturnQuotaStreamOnWrite(){
+               $instance = $this->getLimitedStorage(9);
+               $stream = $instance->fopen('foo', 'w+');
+               $meta = stream_get_meta_data($stream);
+               $this->assertEquals('user-space', $meta['wrapper_type']);
+               fclose($stream);
+       }
 }