diff --git a/lib/private/Preview/BackgroundCleanupJob.php b/lib/private/Preview/BackgroundCleanupJob.php index 8449e73983cb7..9cee4c5c30c03 100644 --- a/lib/private/Preview/BackgroundCleanupJob.php +++ b/lib/private/Preview/BackgroundCleanupJob.php @@ -76,13 +76,13 @@ private function getOldPreviewLocations(): \Iterator { $qb->expr()->castColumn('a.name', IQueryBuilder::PARAM_INT), 'b.fileid' )) ->where( - $qb->expr()->isNull('b.fileid') - )->andWhere( - $qb->expr()->eq('a.storage', $qb->createNamedParameter($this->previewFolder->getStorageId())) - )->andWhere( - $qb->expr()->eq('a.parent', $qb->createNamedParameter($this->previewFolder->getId())) - )->andWhere( - $qb->expr()->like('a.name', $qb->createNamedParameter('__%')) + $qb->expr()->andX( + $qb->expr()->isNull('b.fileid'), + $qb->expr()->eq('a.storage', $qb->createNamedParameter($this->previewFolder->getStorageId())), + $qb->expr()->eq('a.parent', $qb->createNamedParameter($this->previewFolder->getId())), + $qb->expr()->like('a.name', $qb->createNamedParameter('__%')), + $qb->expr()->eq('a.mimetype', $qb->createNamedParameter($this->mimeTypeLoader->getId('httpd/unix-directory'))) + ) ); if (!$this->isCLI) { diff --git a/tests/lib/Preview/BackgroundCleanupJobTest.php b/tests/lib/Preview/BackgroundCleanupJobTest.php index 9c521376af5ad..7c7d458164fdf 100644 --- a/tests/lib/Preview/BackgroundCleanupJobTest.php +++ b/tests/lib/Preview/BackgroundCleanupJobTest.php @@ -191,13 +191,23 @@ public function testOldPreviews(): void { $f2 = $appdata->newFolder((string)PHP_INT_MAX - 1); $f2->newFile('foo.jpg', 'foo'); + /* + * Cleanup of OldPreviewLocations should only remove folders on AppData level, + * therefore this file should stay untouched. + */ + $appdata->getAppDataFolder()->newFile('not-a-directory', 'foo'); + $appdata = \OC::$server->getAppDataDir('preview'); - $this->assertSame(3, count($appdata->getDirectoryListing())); + $this->assertSame(4, count($appdata->getDirectoryListing())); $job = new BackgroundCleanupJob($this->timeFactory, $this->connection, $this->getRoot(), $this->mimeTypeLoader, true); $job->run([]); $appdata = \OC::$server->getAppDataDir('preview'); - $this->assertSame(0, count($appdata->getDirectoryListing())); + + // Check if the `not-a-directory` file is still present + $directoryListing = $appdata->getDirectoryListing(); + $this->assertSame(1, count($directoryListing)); + $this->assertSame('not-a-directory', $directoryListing[0]->getName()); } }