Skip to content

Commit 95c6a91

Browse files
authored
Merge pull request #22554 from nextcloud/backport/22528/stable18
[stable18] Change free space calculation
2 parents ce93aaf + 062ce54 commit 95c6a91

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

apps/files_trashbin/lib/Trashbin.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,11 +712,13 @@ public static function deleteUser($uid) {
712712
*/
713713
private static function calculateFreeSpace($trashbinSize, $user) {
714714
$config = \OC::$server->getConfig();
715-
$systemTrashbinSize = (int)$config->getAppValue('files_trashbin', 'trashbin_size', '-1');
716715
$userTrashbinSize = (int)$config->getUserValue($user, 'files_trashbin', 'trashbin_size', '-1');
717-
$configuredTrashbinSize = ($userTrashbinSize < 0) ? $systemTrashbinSize : $userTrashbinSize;
718-
if ($configuredTrashbinSize) {
719-
return $configuredTrashbinSize - $trashbinSize;
716+
if ($userTrashbinSize > -1) {
717+
return $userTrashbinSize - $trashbinSize;
718+
}
719+
$systemTrashbinSize = (int)$config->getAppValue('files_trashbin', 'trashbin_size', '-1');
720+
if ($systemTrashbinSize > -1) {
721+
return $systemTrashbinSize - $trashbinSize;
720722
}
721723

722724
$softQuota = true;

apps/files_trashbin/tests/TrashbinTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,25 @@ protected function setUp(): void {
120120
\OC::$server->getAppManager()->enableApp('files_trashbin');
121121
$config = \OC::$server->getConfig();
122122
$mockConfig = $this->createMock(\OCP\IConfig::class);
123-
$mockConfig->expects($this->any())
123+
$mockConfig
124124
->method('getSystemValue')
125-
->will($this->returnCallback(function ($key, $default) use ($config) {
125+
->will($this->returnCallback(static function ($key, $default) use ($config) {
126126
if ($key === 'filesystem_check_changes') {
127127
return \OC\Files\Cache\Watcher::CHECK_ONCE;
128128
} else {
129129
return $config->getSystemValue($key, $default);
130130
}
131131
}));
132+
$mockConfig
133+
->method('getUserValue')
134+
->willReturnCallback(static function ($userId, $appName, $key, $default = '') use ($config) {
135+
return $config->getUserValue($userId, $appName, $key, $default);
136+
});
137+
$mockConfig
138+
->method('getAppValue')
139+
->willReturnCallback(static function ($appName, $key, $default = '') use ($config) {
140+
return $config->getAppValue($appName, $key, $default);
141+
});
132142
$this->overwriteService('AllConfig', $mockConfig);
133143

134144
$this->trashRoot1 = '/' . self::TEST_TRASHBIN_USER1 . '/files_trashbin';

0 commit comments

Comments
 (0)