summaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/lib
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2023-06-08 14:52:30 +0200
committerJohn Molakvoæ <skjnldsv@protonmail.com>2023-06-09 08:40:54 +0200
commit9330739014cd4bc5bf3fea67fa961a07feff6dbd (patch)
treee0833a72ab43c3f8b32167208367f1c1d8c74dfd /apps/files_trashbin/lib
parent71adc305dc29a8a946a46cb7c61fd5fb34d6b123 (diff)
downloadnextcloud-server-9330739014cd4bc5bf3fea67fa961a07feff6dbd.tar.gz
nextcloud-server-9330739014cd4bc5bf3fea67fa961a07feff6dbd.zip
Correctly react to bad configuration
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps/files_trashbin/lib')
-rw-r--r--apps/files_trashbin/lib/Trashbin.php36
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