Skip to content

Commit

Permalink
Use system helper to get free space
Browse files Browse the repository at this point in the history
  • Loading branch information
VicDeo committed Dec 2, 2019
1 parent bf5874c commit 3c02e6c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
26 changes: 17 additions & 9 deletions apps/files_trashbin/lib/Quota.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -84,21 +83,30 @@ 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) {
$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) {
$storage = $rootInfo->getStorage();
$free = $storage->free_space('');
} else {
$free = 0;
}
}

return $quota;
return $free;
}
}
5 changes: 5 additions & 0 deletions changelog/unreleased/36494
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3c02e6c

Please sign in to comment.