From d6b7ad7109149d26bb34b8128f74a99f856d3963 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Mon, 31 Aug 2020 23:10:04 +0200 Subject: [PATCH 1/2] Change free space calculation Signed-off-by: Daniel Kesselberg --- apps/files_trashbin/lib/Trashbin.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php index 27242a972d160..035919f55d067 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -712,11 +712,13 @@ public static function deleteUser($uid) { */ private static function calculateFreeSpace($trashbinSize, $user) { $config = \OC::$server->getConfig(); - $systemTrashbinSize = (int)$config->getAppValue('files_trashbin', 'trashbin_size', '-1'); $userTrashbinSize = (int)$config->getUserValue($user, 'files_trashbin', 'trashbin_size', '-1'); - $configuredTrashbinSize = ($userTrashbinSize < 0) ? $systemTrashbinSize : $userTrashbinSize; - if ($configuredTrashbinSize) { - return $configuredTrashbinSize - $trashbinSize; + if ($userTrashbinSize > -1) { + return $userTrashbinSize - $trashbinSize; + } + $systemTrashbinSize = (int)$config->getAppValue('files_trashbin', 'trashbin_size', '-1'); + if ($systemTrashbinSize > -1) { + return $systemTrashbinSize - $trashbinSize; } $softQuota = true; From 062ce5444dfbb55cf93359c232d2e6e315b91593 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Tue, 1 Sep 2020 09:58:59 +0200 Subject: [PATCH 2/2] Tests only: Forward calls to getUserValue and getAppValue Signed-off-by: Daniel Kesselberg --- apps/files_trashbin/tests/TrashbinTest.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/files_trashbin/tests/TrashbinTest.php b/apps/files_trashbin/tests/TrashbinTest.php index 1e0414983905c..806a8b765a096 100644 --- a/apps/files_trashbin/tests/TrashbinTest.php +++ b/apps/files_trashbin/tests/TrashbinTest.php @@ -120,15 +120,25 @@ protected function setUp(): void { \OC::$server->getAppManager()->enableApp('files_trashbin'); $config = \OC::$server->getConfig(); $mockConfig = $this->createMock(\OCP\IConfig::class); - $mockConfig->expects($this->any()) + $mockConfig ->method('getSystemValue') - ->will($this->returnCallback(function ($key, $default) use ($config) { + ->will($this->returnCallback(static function ($key, $default) use ($config) { if ($key === 'filesystem_check_changes') { return \OC\Files\Cache\Watcher::CHECK_ONCE; } else { return $config->getSystemValue($key, $default); } })); + $mockConfig + ->method('getUserValue') + ->willReturnCallback(static function ($userId, $appName, $key, $default = '') use ($config) { + return $config->getUserValue($userId, $appName, $key, $default); + }); + $mockConfig + ->method('getAppValue') + ->willReturnCallback(static function ($appName, $key, $default = '') use ($config) { + return $config->getAppValue($appName, $key, $default); + }); $this->overwriteService('AllConfig', $mockConfig); $this->trashRoot1 = '/' . self::TEST_TRASHBIN_USER1 . '/files_trashbin';