Skip to content

Commit

Permalink
Get free space from storage
Browse files Browse the repository at this point in the history
  • Loading branch information
VicDeo committed Dec 3, 2019
1 parent 24443e5 commit 9a0bb06
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
24 changes: 15 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,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;
}
}
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 9a0bb06

Please sign in to comment.