Skip to content

Commit 4b02134

Browse files
artongebackportbot[bot]
authored andcommitted
fix: Catch exceptions when expiring trashbin
Signed-off-by: Louis Chemineau <louis@chmn.me> [skip ci]
1 parent 5b8233d commit 4b02134

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use OCP\BackgroundJob\TimedJob;
3434
use OCP\IAppConfig;
3535
use OCP\IUserManager;
36+
use Psr\Log\LoggerInterface;
3637

3738
class ExpireTrash extends TimedJob {
3839

@@ -63,12 +64,16 @@ protected function run($argument) {
6364
$users = $this->userManager->getSeenUsers($offset);
6465

6566
foreach ($users as $user) {
66-
$uid = $user->getUID();
67-
if (!$this->setupFS($uid)) {
68-
continue;
67+
try {
68+
$uid = $user->getUID();
69+
if (!$this->setupFS($uid)) {
70+
continue;
71+
}
72+
$dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
73+
Trashbin::deleteExpiredFiles($dirContent, $uid);
74+
} catch (\Throwable $e) {
75+
$this->logger->error('Error while expiring trashbin for user ' . $user->getUID(), ['exception' => $e]);
6976
}
70-
$dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
71-
Trashbin::deleteExpiredFiles($dirContent, $uid);
7277

7378
$offset++;
7479

apps/files_trashbin/lib/Command/ExpireTrash.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use OCA\Files_Trashbin\Trashbin;
3131
use OCP\IUser;
3232
use OCP\IUserManager;
33+
use Psr\Log\LoggerInterface;
3334
use Symfony\Component\Console\Command\Command;
3435
use Symfony\Component\Console\Helper\ProgressBar;
3536
use Symfony\Component\Console\Input\InputArgument;
@@ -104,12 +105,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
104105
}
105106

106107
public function expireTrashForUser(IUser $user) {
107-
$uid = $user->getUID();
108-
if (!$this->setupFS($uid)) {
109-
return;
108+
try {
109+
$uid = $user->getUID();
110+
if (!$this->setupFS($uid)) {
111+
return;
112+
}
113+
$dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
114+
Trashbin::deleteExpiredFiles($dirContent, $uid);
115+
} catch (\Throwable $e) {
116+
$this->logger->error('Error while expiring trashbin for user ' . $user->getUID(), ['exception' => $e]);
110117
}
111-
$dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
112-
Trashbin::deleteExpiredFiles($dirContent, $uid);
113118
}
114119

115120
/**

apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use OCP\IAppConfig;
3333
use OCP\IUserManager;
3434
use PHPUnit\Framework\MockObject\MockObject;
35+
use Psr\Log\LoggerInterface;
3536
use Test\TestCase;
3637

3738
class ExpireTrashTest extends TestCase {
@@ -47,6 +48,9 @@ class ExpireTrashTest extends TestCase {
4748
/** @var IJobList&MockObject */
4849
private $jobList;
4950

51+
/** @var LoggerInterface&MockObject */
52+
private $logger;
53+
5054
/** @var ITimeFactory&MockObject */
5155
private $time;
5256

@@ -57,6 +61,7 @@ protected function setUp(): void {
5761
$this->userManager = $this->createMock(IUserManager::class);
5862
$this->expiration = $this->createMock(Expiration::class);
5963
$this->jobList = $this->createMock(IJobList::class);
64+
$this->logger = $this->createMock(LoggerInterface::class);
6065

6166
$this->time = $this->createMock(ITimeFactory::class);
6267
$this->time->method('getTime')
@@ -76,7 +81,7 @@ public function testConstructAndRun(): void {
7681
->with('files_trashbin', 'background_job_expire_trash_offset', 0)
7782
->willReturn(0);
7883

79-
$job = new ExpireTrash($this->appConfig, $this->userManager, $this->expiration, $this->time);
84+
$job = new ExpireTrash($this->appConfig, $this->userManager, $this->expiration, $this->logger, $this->time);
8085
$job->start($this->jobList);
8186
}
8287

@@ -87,7 +92,7 @@ public function testBackgroundJobDeactivated(): void {
8792
$this->expiration->expects($this->never())
8893
->method('getMaxAgeAsTimestamp');
8994

90-
$job = new ExpireTrash($this->appConfig, $this->userManager, $this->expiration, $this->time);
95+
$job = new ExpireTrash($this->appConfig, $this->userManager, $this->expiration, $this->logger, $this->time);
9196
$job->start($this->jobList);
9297
}
9398
}

0 commit comments

Comments
 (0)