From 9a0bb06ffd744a9d66e168ce3e1aba7227b39309 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Fri, 29 Nov 2019 17:25:28 +0300 Subject: [PATCH] Get free space from storage --- apps/files_trashbin/lib/Quota.php | 24 +++++++++++++++--------- changelog/unreleased/36494 | 5 +++++ 2 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 changelog/unreleased/36494 diff --git a/apps/files_trashbin/lib/Quota.php b/apps/files_trashbin/lib/Quota.php index 28eac7991f7f..93cf0657be88 100644 --- a/apps/files_trashbin/lib/Quota.php +++ b/apps/files_trashbin/lib/Quota.php @@ -55,14 +55,13 @@ public function calculateFreeSpace($trashbinSize, $user) { if ($userObject === null) { return 0; } - $quota = $this->getUserQuota($userObject); $userFolder = \OC::$server->getUserFolder($user); if ($userFolder === null) { return 0; } - $free = $quota - $userFolder->getSize(); // remaining free space for user + $free = $this->getFreeSpace($userObject); if ($free > 0) { // does trashbin size hit purge limit with the current free space $availableSpace = ($free * $this->getPurgeLimit() / 100) - $trashbinSize; @@ -84,21 +83,28 @@ public function getPurgeLimit() { } /** - * Get user quota or free space when there is no quota set + * Get free space for the current user + * or free disk space if the current user has no quota set * * @param IUser $user - * @return int|mixed + * @return int */ - protected function getUserQuota(IUser $user) { + protected function getFreeSpace(IUser $user) { + $free = 0; $quota = \OC_Util::getUserQuota($user); if ($quota === FileInfo::SPACE_UNLIMITED) { - $quota = Filesystem::free_space('/'); + $free = Filesystem::free_space('/'); // inf or unknown free space - if ($quota < 0) { - $quota = PHP_INT_MAX; + if ($free < 0) { + $free = PHP_INT_MAX; + } + } else { + $rootInfo = \OC\Files\Filesystem::getFileInfo('/', false); + if ($rootInfo instanceof FileInfo) { + $free = $rootInfo->getStorage()->free_space(''); } } - return $quota; + return $free; } } diff --git a/changelog/unreleased/36494 b/changelog/unreleased/36494 new file mode 100644 index 000000000000..1bf8b88f6e5e --- /dev/null +++ b/changelog/unreleased/36494 @@ -0,0 +1,5 @@ +Bugfix: Files shared with user cause purge of the trashbin content + +Files_thrashbin app counted incoming shares on calculation of the occupied space. It caused purge of the trashbin content when trashbin_retention_obligation is auto, user has quota set and incoming shares exceed 50% of this quota. + +https://github.com/owncloud/core/pull/36494