From 195d347240ed370d2ddcfc8f985c35bebe83ab8c Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 14 Oct 2025 10:58:26 +0200 Subject: [PATCH 1/2] fix(trashbin): make sure the trashed files are deleted if we don't have any available space left Logic taken from the files_versions expiration. It seems the second argument from the isExpired method wasn't even used anywhere. Signed-off-by: Thomas Citharel --- apps/files_trashbin/lib/Trashbin.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php index dd71e8ec28e..7299326ecf1 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -844,7 +844,7 @@ class Trashbin implements IEventListener { $dirContent = Helper::getTrashFiles('/', $user, 'mtime'); // delete all files older then $retention_obligation - [$delSize, $count] = self::deleteExpiredFiles($dirContent, $user); + [$delSize, $count] = self::deleteExpiredFiles($dirContent, $user, $availableSpace <= 0); $availableSpace += $delSize; @@ -906,9 +906,10 @@ class Trashbin implements IEventListener { * * @param array $files list of files sorted by mtime * @param string $user + * @param bool $quotaExceeded * @return array{int|float, int} size of deleted files and number of deleted files */ - public static function deleteExpiredFiles($files, $user) { + public static function deleteExpiredFiles($files, $user, bool $quotaExceeded = false) { /** @var Expiration $expiration */ $expiration = Server::get(Expiration::class); $size = 0; @@ -916,7 +917,7 @@ class Trashbin implements IEventListener { foreach ($files as $file) { $timestamp = $file['mtime']; $filename = $file['name']; - if ($expiration->isExpired($timestamp)) { + if ($expiration->isExpired($timestamp, $quotaExceeded)) { try { $size += self::delete($filename, $user, $timestamp); $count++; From cea23fb53d58e5173f745adf61f22345651cca1f Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 14 Oct 2025 11:07:25 +0200 Subject: [PATCH 2/2] refactor(trashbin): make the ExpireTrash background job use the Trashbin::expire static method Instead of handling everything itself, and so that the available space is considered in deleting trashed files even if not expired yet. Signed-off-by: Thomas Citharel --- apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php index 9a2186d79a4..3c558208792 100644 --- a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php +++ b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php @@ -11,7 +11,6 @@ use OC\Files\SetupManager; use OC\Files\View; use OCA\Files_Trashbin\AppInfo\Application; use OCA\Files_Trashbin\Expiration; -use OCA\Files_Trashbin\Helper; use OCA\Files_Trashbin\Trashbin; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\TimedJob; @@ -66,8 +65,7 @@ class ExpireTrash extends TimedJob { try { if ($this->setupFS($user)) { - $dirContent = Helper::getTrashFiles('/', $uid, 'mtime'); - Trashbin::deleteExpiredFiles($dirContent, $uid); + Trashbin::expire($uid); } } catch (\Throwable $e) { $this->logger->error('Error while expiring trashbin for user ' . $uid, ['exception' => $e]);