diff options
Diffstat (limited to 'lib/private/Files/Storage/Wrapper/Quota.php')
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Quota.php | 82 |
1 files changed, 21 insertions, 61 deletions
diff --git a/lib/private/Files/Storage/Wrapper/Quota.php b/lib/private/Files/Storage/Wrapper/Quota.php index 8c6799fdd2d..35a265f8c8e 100644 --- a/lib/private/Files/Storage/Wrapper/Quota.php +++ b/lib/private/Files/Storage/Wrapper/Quota.php @@ -21,11 +21,12 @@ class Quota extends Wrapper { protected string $sizeRoot; private SystemConfig $config; private bool $quotaIncludeExternalStorage; + private bool $enabled = true; /** * @param array $parameters */ - public function __construct($parameters) { + public function __construct(array $parameters) { parent::__construct($parameters); $this->quota = $parameters['quota'] ?? null; $this->quotaCallback = $parameters['quotaCallback'] ?? null; @@ -33,14 +34,11 @@ class Quota extends Wrapper { $this->quotaIncludeExternalStorage = $parameters['include_external_storage'] ?? false; } - /** - * @return int|float quota value - */ public function getQuota(): int|float { if ($this->quota === null) { $quotaCallback = $this->quotaCallback; if ($quotaCallback === null) { - throw new \Exception("No quota or quota callback provider"); + throw new \Exception('No quota or quota callback provider'); } $this->quota = $quotaCallback(); } @@ -49,15 +47,13 @@ class Quota extends Wrapper { } private function hasQuota(): bool { + if (!$this->enabled) { + return false; + } return $this->getQuota() !== FileInfo::SPACE_UNLIMITED; } - /** - * @param string $path - * @param IStorage $storage - * @return int|float - */ - protected function getSize($path, $storage = null) { + protected function getSize(string $path, ?IStorage $storage = null): int|float { if ($this->quotaIncludeExternalStorage) { $rootInfo = Filesystem::getFileInfo('', 'ext'); if ($rootInfo) { @@ -75,13 +71,7 @@ class Quota extends Wrapper { } } - /** - * Get free space as limited by the quota - * - * @param string $path - * @return int|float|bool - */ - public function free_space($path) { + public function free_space(string $path): int|float|false { if (!$this->hasQuota()) { return $this->storage->free_space($path); } @@ -101,14 +91,7 @@ class Quota extends Wrapper { } } - /** - * see https://www.php.net/manual/en/function.file_put_contents.php - * - * @param string $path - * @param mixed $data - * @return int|float|false - */ - public function file_put_contents($path, $data) { + public function file_put_contents(string $path, mixed $data): int|float|false { if (!$this->hasQuota()) { return $this->storage->file_put_contents($path, $data); } @@ -120,14 +103,7 @@ class Quota extends Wrapper { } } - /** - * see https://www.php.net/manual/en/function.copy.php - * - * @param string $source - * @param string $target - * @return bool - */ - public function copy($source, $target) { + public function copy(string $source, string $target): bool { if (!$this->hasQuota()) { return $this->storage->copy($source, $target); } @@ -139,14 +115,7 @@ class Quota extends Wrapper { } } - /** - * see https://www.php.net/manual/en/function.fopen.php - * - * @param string $path - * @param string $mode - * @return resource|bool - */ - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { if (!$this->hasQuota()) { return $this->storage->fopen($path, $mode); } @@ -170,10 +139,9 @@ class Quota extends Wrapper { * Checks whether the given path is a part file * * @param string $path Path that may identify a .part file - * @return bool * @note this is needed for reusing keys */ - private function isPartFile($path) { + private function isPartFile(string $path): bool { $extension = pathinfo($path, PATHINFO_EXTENSION); return ($extension === 'part'); @@ -182,17 +150,11 @@ class Quota extends Wrapper { /** * Only apply quota for files, not metadata, trash or others */ - private function shouldApplyQuota(string $path): bool { + protected function shouldApplyQuota(string $path): bool { return str_starts_with(ltrim($path, '/'), 'files/'); } - /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @return bool - */ - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { if (!$this->hasQuota()) { return $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } @@ -204,13 +166,7 @@ class Quota extends Wrapper { } } - /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @return bool - */ - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { if (!$this->hasQuota()) { return $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } @@ -222,7 +178,7 @@ class Quota extends Wrapper { } } - public function mkdir($path) { + public function mkdir(string $path): bool { if (!$this->hasQuota()) { return $this->storage->mkdir($path); } @@ -234,7 +190,7 @@ class Quota extends Wrapper { return parent::mkdir($path); } - public function touch($path, $mtime = null) { + public function touch(string $path, ?int $mtime = null): bool { if (!$this->hasQuota()) { return $this->storage->touch($path, $mtime); } @@ -245,4 +201,8 @@ class Quota extends Wrapper { return parent::touch($path, $mtime); } + + public function enableQuota(bool $enabled): void { + $this->enabled = $enabled; + } } |