Merge pull request #6962 from owncloud/quota-space-root
Allow passing a root folder to get the used space from in the quota wrapper
This commit is contained in:
commit
ec45a3c0e2
|
@ -15,12 +15,18 @@ class Quota extends Wrapper {
|
||||||
*/
|
*/
|
||||||
protected $quota;
|
protected $quota;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string $sizeRoot
|
||||||
|
*/
|
||||||
|
protected $sizeRoot;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $parameters
|
* @param array $parameters
|
||||||
*/
|
*/
|
||||||
public function __construct($parameters) {
|
public function __construct($parameters) {
|
||||||
$this->storage = $parameters['storage'];
|
$this->storage = $parameters['storage'];
|
||||||
$this->quota = $parameters['quota'];
|
$this->quota = $parameters['quota'];
|
||||||
|
$this->sizeRoot = isset($parameters['root']) ? $parameters['root'] : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,7 +52,7 @@ class Quota extends Wrapper {
|
||||||
if ($this->quota < 0) {
|
if ($this->quota < 0) {
|
||||||
return $this->storage->free_space($path);
|
return $this->storage->free_space($path);
|
||||||
} else {
|
} else {
|
||||||
$used = $this->getSize('');
|
$used = $this->getSize($this->sizeRoot);
|
||||||
if ($used < 0) {
|
if ($used < 0) {
|
||||||
return \OC\Files\SPACE_NOT_COMPUTED;
|
return \OC\Files\SPACE_NOT_COMPUTED;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -231,7 +231,7 @@ class OC_Image {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns Returns the image resource in any.
|
* @returns resource Returns the image resource in any.
|
||||||
*/
|
*/
|
||||||
public function resource() {
|
public function resource() {
|
||||||
return $this->resource;
|
return $this->resource;
|
||||||
|
|
|
@ -65,7 +65,7 @@ class OC_Util {
|
||||||
$user = $storage->getUser()->getUID();
|
$user = $storage->getUser()->getUID();
|
||||||
$quota = OC_Util::getUserQuota($user);
|
$quota = OC_Util::getUserQuota($user);
|
||||||
if ($quota !== \OC\Files\SPACE_UNLIMITED) {
|
if ($quota !== \OC\Files\SPACE_UNLIMITED) {
|
||||||
return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota));
|
return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ class Quota extends \Test\Files\Storage\Storage {
|
||||||
$this->assertEquals('foobarqwe', $instance->file_get_contents('foo'));
|
$this->assertEquals('foobarqwe', $instance->file_get_contents('foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReturnFalseWhenFopenFailed(){
|
public function testReturnFalseWhenFopenFailed() {
|
||||||
$failStorage = $this->getMock(
|
$failStorage = $this->getMock(
|
||||||
'\OC\Files\Storage\Local',
|
'\OC\Files\Storage\Local',
|
||||||
array('fopen'),
|
array('fopen'),
|
||||||
|
@ -76,7 +76,7 @@ class Quota extends \Test\Files\Storage\Storage {
|
||||||
$this->assertFalse($instance->fopen('failedfopen', 'r'));
|
$this->assertFalse($instance->fopen('failedfopen', 'r'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReturnRegularStreamOnRead(){
|
public function testReturnRegularStreamOnRead() {
|
||||||
$instance = $this->getLimitedStorage(9);
|
$instance = $this->getLimitedStorage(9);
|
||||||
|
|
||||||
// create test file first
|
// create test file first
|
||||||
|
@ -95,11 +95,30 @@ class Quota extends \Test\Files\Storage\Storage {
|
||||||
fclose($stream);
|
fclose($stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReturnQuotaStreamOnWrite(){
|
public function testReturnQuotaStreamOnWrite() {
|
||||||
$instance = $this->getLimitedStorage(9);
|
$instance = $this->getLimitedStorage(9);
|
||||||
$stream = $instance->fopen('foo', 'w+');
|
$stream = $instance->fopen('foo', 'w+');
|
||||||
$meta = stream_get_meta_data($stream);
|
$meta = stream_get_meta_data($stream);
|
||||||
$this->assertEquals('user-space', $meta['wrapper_type']);
|
$this->assertEquals('user-space', $meta['wrapper_type']);
|
||||||
fclose($stream);
|
fclose($stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSpaceRoot() {
|
||||||
|
$storage = $this->getMockBuilder('\OC\Files\Storage\Local')->disableOriginalConstructor()->getMock();
|
||||||
|
$cache = $this->getMockBuilder('\OC\Files\Cache\Cache')->disableOriginalConstructor()->getMock();
|
||||||
|
$storage->expects($this->once())
|
||||||
|
->method('getCache')
|
||||||
|
->will($this->returnValue($cache));
|
||||||
|
$storage->expects($this->once())
|
||||||
|
->method('free_space')
|
||||||
|
->will($this->returnValue(2048));
|
||||||
|
$cache->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with('files')
|
||||||
|
->will($this->returnValue(array('size' => 50)));
|
||||||
|
|
||||||
|
$instance = new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => 1024, 'root' => 'files'));
|
||||||
|
|
||||||
|
$this->assertEquals(1024 - 50, $instance->free_space(''));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue