Skip to content

Commit a36ebef

Browse files
authored
Merge pull request #55742 from nextcloud/fix-trashbin-expiration
fix(trashbin): make sure the trashed files are deleted if we don't have any available space left
2 parents 35f9d6f + cea23fb commit a36ebef

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use OC\Files\View;
1212
use OCA\Files_Trashbin\AppInfo\Application;
1313
use OCA\Files_Trashbin\Expiration;
14-
use OCA\Files_Trashbin\Helper;
1514
use OCA\Files_Trashbin\Trashbin;
1615
use OCP\AppFramework\Utility\ITimeFactory;
1716
use OCP\BackgroundJob\TimedJob;
@@ -66,8 +65,7 @@ protected function run($argument) {
6665

6766
try {
6867
if ($this->setupFS($user)) {
69-
$dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
70-
Trashbin::deleteExpiredFiles($dirContent, $uid);
68+
Trashbin::expire($uid);
7169
}
7270
} catch (\Throwable $e) {
7371
$this->logger->error('Error while expiring trashbin for user ' . $uid, ['exception' => $e]);

apps/files_trashbin/lib/Trashbin.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ public static function expire($user) {
844844
$dirContent = Helper::getTrashFiles('/', $user, 'mtime');
845845

846846
// delete all files older then $retention_obligation
847-
[$delSize, $count] = self::deleteExpiredFiles($dirContent, $user);
847+
[$delSize, $count] = self::deleteExpiredFiles($dirContent, $user, $availableSpace <= 0);
848848

849849
$availableSpace += $delSize;
850850

@@ -906,17 +906,18 @@ protected static function deleteFiles(array $files, string $user, int|float $ava
906906
*
907907
* @param array $files list of files sorted by mtime
908908
* @param string $user
909+
* @param bool $quotaExceeded
909910
* @return array{int|float, int} size of deleted files and number of deleted files
910911
*/
911-
public static function deleteExpiredFiles($files, $user) {
912+
public static function deleteExpiredFiles($files, $user, bool $quotaExceeded = false) {
912913
/** @var Expiration $expiration */
913914
$expiration = Server::get(Expiration::class);
914915
$size = 0;
915916
$count = 0;
916917
foreach ($files as $file) {
917918
$timestamp = $file['mtime'];
918919
$filename = $file['name'];
919-
if ($expiration->isExpired($timestamp)) {
920+
if ($expiration->isExpired($timestamp, $quotaExceeded)) {
920921
try {
921922
$size += self::delete($filename, $user, $timestamp);
922923
$count++;

0 commit comments

Comments
 (0)