]> source.dussan.org Git - nextcloud-server.git/commitdiff
Still return quota value when free space is unknown
authorVincent Petry <pvince81@owncloud.com>
Wed, 19 Mar 2014 18:07:11 +0000 (19:07 +0100)
committerVincent Petry <pvince81@owncloud.com>
Wed, 19 Mar 2014 18:07:11 +0000 (19:07 +0100)
Fixed the quota storage wrapper to correctly return the quota value when
the free space is not known (which usually happens when the disk_free_space
function is disabled)

lib/private/files/storage/wrapper/quota.php
tests/lib/files/storage/wrapper/quota.php

index 32ceba8b196d6ac36859455aa1e6ab10cd39cb1e..a878b2c5cf6c8d27798c9b1185f9aa257f8172af 100644 (file)
@@ -69,7 +69,14 @@ class Quota extends Wrapper {
                                return \OC\Files\SPACE_NOT_COMPUTED;
                        } else {
                                $free = $this->storage->free_space($path);
-                               return min($free, (max($this->quota - $used, 0)));
+                               $quotaFree = max($this->quota - $used, 0);
+                               // if free space is known
+                               if ($free >= 0) {
+                                       $free = min($free, $quotaFree);
+                               } else {
+                                       $free = $quotaFree;
+                               }
+                               return $free;
                        }
                }
        }
index bd2c69a7396a000aff04963ac7072472a5664fcf..777529fd85ef03268cc19e3403c2cc2b98799a21 100644 (file)
@@ -61,6 +61,24 @@ class Quota extends \Test\Files\Storage\Storage {
                $this->assertEquals(6, $instance->free_space(''));
        }
 
+       public function testFreeSpaceWithUnknownDiskSpace() {
+               $storage = $this->getMock(
+                       '\OC\Files\Storage\Local',
+                       array('free_space'),
+                       array(array('datadir' => $this->tmpDir))
+               );
+               $storage->expects($this->any())
+                       ->method('free_space')
+                       ->will($this->returnValue(-2));
+               $storage->getScanner()->scan('');
+
+               $instance = new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => 9));
+               $instance->getCache()->put(
+                       '', array('size' => 3, 'unencrypted_size' => 0)
+               );
+               $this->assertEquals(6, $instance->free_space(''));
+       }
+
        public function testFreeSpaceWithUsedSpaceAndEncryption() {
                $instance = $this->getLimitedStorage(9);
                $instance->getCache()->put(