X Tutup
Skip to content

Commit 9a0bb06

Browse files
committed
Get free space from storage
1 parent 24443e5 commit 9a0bb06

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

apps/files_trashbin/lib/Quota.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,13 @@ public function calculateFreeSpace($trashbinSize, $user) {
5555
if ($userObject === null) {
5656
return 0;
5757
}
58-
$quota = $this->getUserQuota($userObject);
5958

6059
$userFolder = \OC::$server->getUserFolder($user);
6160
if ($userFolder === null) {
6261
return 0;
6362
}
6463

65-
$free = $quota - $userFolder->getSize(); // remaining free space for user
64+
$free = $this->getFreeSpace($userObject);
6665
if ($free > 0) {
6766
// does trashbin size hit purge limit with the current free space
6867
$availableSpace = ($free * $this->getPurgeLimit() / 100) - $trashbinSize;
@@ -84,21 +83,28 @@ public function getPurgeLimit() {
8483
}
8584

8685
/**
87-
* Get user quota or free space when there is no quota set
86+
* Get free space for the current user
87+
* or free disk space if the current user has no quota set
8888
*
8989
* @param IUser $user
90-
* @return int|mixed
90+
* @return int
9191
*/
92-
protected function getUserQuota(IUser $user) {
92+
protected function getFreeSpace(IUser $user) {
93+
$free = 0;
9394
$quota = \OC_Util::getUserQuota($user);
9495
if ($quota === FileInfo::SPACE_UNLIMITED) {
95-
$quota = Filesystem::free_space('/');
96+
$free = Filesystem::free_space('/');
9697
// inf or unknown free space
97-
if ($quota < 0) {
98-
$quota = PHP_INT_MAX;
98+
if ($free < 0) {
99+
$free = PHP_INT_MAX;
100+
}
101+
} else {
102+
$rootInfo = \OC\Files\Filesystem::getFileInfo('/', false);
103+
if ($rootInfo instanceof FileInfo) {
104+
$free = $rootInfo->getStorage()->free_space('');
99105
}
100106
}
101107

102-
return $quota;
108+
return $free;
103109
}
104110
}

changelog/unreleased/36494

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Bugfix: Files shared with user cause purge of the trashbin content
2+
3+
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.
4+
5+
https://github.com/owncloud/core/pull/36494

0 commit comments

Comments
 (0)
X Tutup