Still return quota value when free space is unknown

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)

Backport of 66bc0f0 from master
This commit is contained in:
Vincent Petry 2014-03-20 17:36:50 +01:00
parent eacb4b3f3e
commit bb995c53c5
2 changed files with 26 additions and 1 deletions

View file

@ -53,7 +53,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;
}
}
}

View file

@ -58,6 +58,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(