From 0a585b004855d5906dbd8dac17d03b4a64fcefc7 Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Wed, 2 Apr 2025 12:45:00 +0200 Subject: fix: Catch exceptions when expiring trashbin Signed-off-by: Louis Chemineau --- apps/files_trashbin/lib/Command/ExpireTrash.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'apps/files_trashbin/lib/Command') diff --git a/apps/files_trashbin/lib/Command/ExpireTrash.php b/apps/files_trashbin/lib/Command/ExpireTrash.php index 2dd02807cfd..de1c2ab09b4 100644 --- a/apps/files_trashbin/lib/Command/ExpireTrash.php +++ b/apps/files_trashbin/lib/Command/ExpireTrash.php @@ -12,6 +12,7 @@ use OCA\Files_Trashbin\Helper; use OCA\Files_Trashbin\Trashbin; use OCP\IUser; use OCP\IUserManager; +use Psr\Log\LoggerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputArgument; @@ -25,6 +26,7 @@ class ExpireTrash extends Command { * @param Expiration|null $expiration */ public function __construct( + private LoggerInterface $logger, private ?IUserManager $userManager = null, private ?Expiration $expiration = null, ) { @@ -77,12 +79,16 @@ class ExpireTrash extends Command { } public function expireTrashForUser(IUser $user) { - $uid = $user->getUID(); - if (!$this->setupFS($uid)) { - return; + try { + $uid = $user->getUID(); + if (!$this->setupFS($uid)) { + return; + } + $dirContent = Helper::getTrashFiles('/', $uid, 'mtime'); + Trashbin::deleteExpiredFiles($dirContent, $uid); + } catch (\Throwable $e) { + $this->logger->error('Error while expiring trashbin for user ' . $user->getUID(), ['exception' => $e]); } - $dirContent = Helper::getTrashFiles('/', $uid, 'mtime'); - Trashbin::deleteExpiredFiles($dirContent, $uid); } /** -- cgit v1.2.3