Skip to content

Commit 357a6ee

Browse files
CarlSchwanbackportbot[bot]
authored andcommitted
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>
1 parent 5875320 commit 357a6ee

3 files changed

Lines changed: 12 additions & 32 deletions

File tree

core/BackgroundJobs/PreviewMigrationJob.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ protected function run(mixed $argument): void {
5151
$qb = $this->connection->getQueryBuilder();
5252
$qb->select('path')
5353
->from('filecache')
54-
// Hierarchical preview folder structure
55-
->where($qb->expr()->like('path', $qb->createNamedParameter($this->previewRootPath . '%/%/%/%/%/%/%/%/%')))
56-
// Legacy flat preview folder structure
57-
->orWhere($qb->expr()->like('path', $qb->createNamedParameter($this->previewRootPath . '%/%.%')))
54+
->where($qb->expr()->orX(
55+
// Hierarchical preview folder structure
56+
$qb->expr()->like('path', $qb->createNamedParameter($this->previewRootPath . '%/%/%/%/%/%/%/%/%')),
57+
// Legacy flat preview folder structure
58+
$qb->expr()->like('path', $qb->createNamedParameter($this->previewRootPath . '%/%.%'))
59+
))->andWhere(
60+
$qb->expr()->eq('storage', $qb->createNamedParameter($this->rootFolder->getMountPoint()->getNumericStorageId()))
61+
)
5862
->hintShardKey('storage', $this->rootFolder->getMountPoint()->getNumericStorageId())
5963
->setMaxResults(100);
6064

core/Command/Preview/Cleanup.php

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

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

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

tests/Core/Command/Preview/CleanupTest.php

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

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

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

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

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

0 commit comments

Comments
 (0)