diff options
Diffstat (limited to 'apps/files_trashbin/lib/Trashbin.php')
-rw-r--r-- | apps/files_trashbin/lib/Trashbin.php | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php index 2779ea157be..90f74e51e81 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -59,6 +59,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; +use OCP\IConfig; use OCP\Lock\ILockingProvider; use OCP\Lock\LockedException; use Psr\Log\LoggerInterface; @@ -304,10 +305,7 @@ class Trashbin { $trashStorage->unlink($trashInternalPath); } - $config = \OC::$server->getConfig(); - $systemTrashbinSize = \OCP\Util::numericToNumber($config->getAppValue('files_trashbin', 'trashbin_size', '-1')); - $userTrashbinSize = \OCP\Util::numericToNumber($config->getUserValue($owner, 'files_trashbin', 'trashbin_size', '-1')); - $configuredTrashbinSize = ($userTrashbinSize < 0) ? $systemTrashbinSize : $userTrashbinSize; + $configuredTrashbinSize = static::getConfiguredTrashbinSize($owner); if ($configuredTrashbinSize >= 0 && $sourceInfo->getSize() >= $configuredTrashbinSize) { return false; } @@ -379,6 +377,19 @@ class Trashbin { return $moveSuccessful; } + private static function getConfiguredTrashbinSize(string $user): int|float { + $config = \OC::$server->get(IConfig::class); + $userTrashbinSize = $config->getUserValue($user, 'files_trashbin', 'trashbin_size', '-1'); + if (is_numeric($userTrashbinSize) && ($userTrashbinSize > -1)) { + return \OCP\Util::numericToNumber($userTrashbinSize); + } + $systemTrashbinSize = $config->getAppValue('files_trashbin', 'trashbin_size', '-1'); + if (is_numeric($systemTrashbinSize)) { + return \OCP\Util::numericToNumber($systemTrashbinSize); + } + return -1; + } + /** * Move file versions to trash so that they can be restored later * @@ -753,21 +764,16 @@ class Trashbin { * @return int|float available free space for trash bin */ private static function calculateFreeSpace(int|float $trashbinSize, string $user): int|float { - $config = \OC::$server->getConfig(); - $userTrashbinSize = \OCP\Util::numericToNumber($config->getUserValue($user, 'files_trashbin', 'trashbin_size', '-1')); - if ($userTrashbinSize > -1) { - return $userTrashbinSize - $trashbinSize; - } - $systemTrashbinSize = \OCP\Util::numericToNumber($config->getAppValue('files_trashbin', 'trashbin_size', '-1')); - if ($systemTrashbinSize > -1) { - return $systemTrashbinSize - $trashbinSize; + $configuredTrashbinSize = static::getConfiguredTrashbinSize($user); + if ($configuredTrashbinSize > -1) { + return $configuredTrashbinSize - $trashbinSize; } - $softQuota = true; $userObject = \OC::$server->getUserManager()->get($user); if (is_null($userObject)) { return 0; } + $softQuota = true; $quota = $userObject->getQuota(); if ($quota === null || $quota === 'none') { $quota = Filesystem::free_space('/'); @@ -778,6 +784,10 @@ class Trashbin { } } else { $quota = \OCP\Util::computerFileSize($quota); + // invalid quota + if ($quota === false) { + $quota = PHP_INT_MAX; + } } // calculate available space for trash bin |