Skip to content

Commit

Permalink
Merge pull request #50474 from nextcloud/backport/48581/stable31
Browse files Browse the repository at this point in the history
[stable31] fix: Filter for folders in cleanup old preview job
  • Loading branch information
AndyScherzinger authored Jan 27, 2025
2 parents 62a74d8 + 72a43a1 commit e916fff
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/private/Preview/BackgroundCleanupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,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) {
Expand Down
31 changes: 31 additions & 0 deletions tests/lib/Preview/BackgroundCleanupJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,44 @@ public function testOldPreviews(): void {
$f2 = $appdata->newFolder((string)PHP_INT_MAX - 1);
$f2->newFile('foo.jpg', 'foo');

/*
* Cleanup of OldPreviewLocations should only remove numeric folders on AppData level,
* therefore these files should stay untouched.
*/
$appdata->getFolder('/')->newFile('not-a-directory', 'foo');
$appdata->getFolder('/')->newFile('133742', 'bar');

$appdata = \OC::$server->getAppDataDir('preview');
// AppData::getDirectoryListing filters all non-folders
$this->assertSame(3, count($appdata->getDirectoryListing()));
try {
$appdata->getFolder('/')->getFile('not-a-directory');
} catch (NotFoundException) {
$this->fail('Could not find file \'not-a-directory\'');
}
try {
$appdata->getFolder('/')->getFile('133742');
} catch (NotFoundException) {
$this->fail('Could not find file \'133742\'');
}

$job = new BackgroundCleanupJob($this->timeFactory, $this->connection, $this->getRoot(), $this->mimeTypeLoader, true);
$job->run([]);

$appdata = \OC::$server->getAppDataDir('preview');

// Check if the files created above are still present
// Remember: AppData::getDirectoryListing filters all non-folders
$this->assertSame(0, count($appdata->getDirectoryListing()));
try {
$appdata->getFolder('/')->getFile('not-a-directory');
} catch (NotFoundException) {
$this->fail('Could not find file \'not-a-directory\'');
}
try {
$appdata->getFolder('/')->getFile('133742');
} catch (NotFoundException) {
$this->fail('Could not find file \'133742\'');
}
}
}

0 comments on commit e916fff

Please sign in to comment.