Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Filter for folders in cleanup old preview job #48581

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/private/Preview/BackgroundCleanupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 12 additions & 2 deletions tests/lib/Preview/BackgroundCleanupJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}