Cache is not part of the quota

Fixes #7444

Since the quota is calculated on the files. We should allow apps etc to
store temp stuff in the <user>/cache

Else users can't upload avatars for example.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2018-05-02 21:46:28 +02:00
parent 2aa108000c
commit f2d05120b4
No known key found for this signature in database
GPG Key ID: F941078878347C0C
1 changed files with 7 additions and 7 deletions

View File

@ -46,7 +46,7 @@ class Quota extends Wrapper {
* @param array $parameters * @param array $parameters
*/ */
public function __construct($parameters) { public function __construct($parameters) {
$this->storage = $parameters['storage']; parent::__construct($parameters);
$this->quota = $parameters['quota']; $this->quota = $parameters['quota'];
$this->sizeRoot = isset($parameters['root']) ? $parameters['root'] : ''; $this->sizeRoot = isset($parameters['root']) ? $parameters['root'] : '';
} }
@ -83,7 +83,7 @@ class Quota extends Wrapper {
* @return int * @return int
*/ */
public function free_space($path) { public function free_space($path) {
if ($this->quota < 0) { if ($this->quota < 0 || strpos($path, 'cache') === 0) {
return $this->storage->free_space($path); return $this->storage->free_space($path);
} else { } else {
$used = $this->getSize($this->sizeRoot); $used = $this->getSize($this->sizeRoot);
@ -111,7 +111,7 @@ class Quota extends Wrapper {
* @return bool * @return bool
*/ */
public function file_put_contents($path, $data) { public function file_put_contents($path, $data) {
$free = $this->free_space(''); $free = $this->free_space($path);
if ($free < 0 or strlen($data) < $free) { if ($free < 0 or strlen($data) < $free) {
return $this->storage->file_put_contents($path, $data); return $this->storage->file_put_contents($path, $data);
} else { } else {
@ -127,7 +127,7 @@ class Quota extends Wrapper {
* @return bool * @return bool
*/ */
public function copy($source, $target) { public function copy($source, $target) {
$free = $this->free_space(''); $free = $this->free_space($target);
if ($free < 0 or $this->getSize($source) < $free) { if ($free < 0 or $this->getSize($source) < $free) {
return $this->storage->copy($source, $target); return $this->storage->copy($source, $target);
} else { } else {
@ -147,7 +147,7 @@ class Quota extends Wrapper {
// don't apply quota for part files // don't apply quota for part files
if (!$this->isPartFile($path)) { if (!$this->isPartFile($path)) {
$free = $this->free_space(''); $free = $this->free_space($path);
if ($source && $free >= 0 && $mode !== 'r' && $mode !== 'rb') { if ($source && $free >= 0 && $mode !== 'r' && $mode !== 'rb') {
// only apply quota for files, not metadata, trash or others // only apply quota for files, not metadata, trash or others
if (strpos(ltrim($path, '/'), 'files/') === 0) { if (strpos(ltrim($path, '/'), 'files/') === 0) {
@ -178,7 +178,7 @@ class Quota extends Wrapper {
* @return bool * @return bool
*/ */
public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
$free = $this->free_space(''); $free = $this->free_space($targetInternalPath);
if ($free < 0 or $this->getSize($sourceInternalPath, $sourceStorage) < $free) { if ($free < 0 or $this->getSize($sourceInternalPath, $sourceStorage) < $free) {
return $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); return $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
} else { } else {
@ -193,7 +193,7 @@ class Quota extends Wrapper {
* @return bool * @return bool
*/ */
public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
$free = $this->free_space(''); $free = $this->free_space($targetInternalPath);
if ($free < 0 or $this->getSize($sourceInternalPath, $sourceStorage) < $free) { if ($free < 0 or $this->getSize($sourceInternalPath, $sourceStorage) < $free) {
return $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); return $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
} else { } else {