Skip to content

Commit bef0841

Browse files
CarlSchwanbackportbot[bot]
authored andcommitted
fix(preview): Don't abort cleanup of previews too early
fix(preview): Don't abort cleanup of previews too early If we don't find previews in the filecache, this is now normal. Don't abort and instead delete previews from the new preview table instead. Signed-off-by: Carl Schwan <carlschwan@kde.org> [skip ci]
1 parent a409b05 commit bef0841

2 files changed

Lines changed: 4 additions & 28 deletions

File tree

core/Command/Preview/Cleanup.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ private function deletePreviewFromFileCacheTable(OutputInterface $output): int {
7575
$previewFolder = $appDataFolder->get('preview');
7676

7777
} catch (NotFoundException $e) {
78-
$this->logger->error("Previews can't be removed: appdata folder can't be found", ['exception' => $e]);
79-
$output->writeln("Previews can't be removed: preview folder isn't deletable");
80-
return 1;
78+
$this->logger->info("Legacy previews can't be removed: appdata folder can't be found", ['exception' => $e]);
79+
return 0;
8180
}
8281

8382
if (!$previewFolder->isDeletable()) {

tests/Core/Command/Preview/CleanupTest.php

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -140,36 +140,13 @@ public static function dataForTestCleanupWithDeleteException(): array {
140140
}
141141

142142
public function testCleanupWithPreviewServiceException(): void {
143-
$previewFolder = $this->createMock(Folder::class);
144-
$previewFolder->expects($this->once())
145-
->method('isDeletable')
146-
->willReturn(true);
147-
148-
$previewFolder->expects($this->once())
149-
->method('delete');
150-
151-
$appDataFolder = $this->createMock(Folder::class);
152-
$appDataFolder->expects($this->once())->method('get')->with('preview')->willReturn($previewFolder);
153-
154143
$this->rootFolder->method('getAppDataDirectoryName')
155-
->willReturn('appdata_some_id');
156-
157-
$this->rootFolder->method('get')
158-
->with('appdata_some_id')
159-
->willReturn($appDataFolder);
160-
161-
$this->output->expects($this->exactly(2))->method('writeln')
162-
->with(self::callback(function (string $message): bool {
163-
static $i = 0;
164-
return match (++$i) {
165-
1 => $message === 'Preview folder deleted',
166-
2 => $message === 'Previews removed'
167-
};
168-
}));
144+
->willThrowException(new NotFoundException());
169145

170146
$this->previewService->expects($this->once())->method('deleteAll')
171147
->willThrowException(new NotPermittedException('abc'));
172148

149+
$this->logger->expects($this->once())->method('info')->with("Legacy previews can't be removed: appdata folder can't be found");
173150
$this->logger->expects($this->once())->method('error')->with("Previews can't be removed: exception occurred: abc");
174151

175152
$this->assertEquals(1, $this->repair->run($this->input, $this->output));

0 commit comments

Comments
 (0)