diff options
author | Dario Mehlich <d.mehlich@gmail.com> | 2025-01-27 10:16:08 +0100 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2025-04-01 11:05:14 +0200 |
commit | b540da607e09510953e8855f7971b1bdc0ce3019 (patch) | |
tree | 5501df21c7564ea4b8ff90561dd95718906553e2 | |
parent | b6f8b51bbe9075d382184d763c722477c44e4033 (diff) | |
download | nextcloud-server-backport/48581/stable29.tar.gz nextcloud-server-backport/48581/stable29.zip |
fix(preview): Filter for folders in cleanup old preview jobbackport/48581/stable29
Fixes #35936.
When running `OC\Preview\BackgroundCleanupJob`, the main iteration loop
in `run()` expects a folder, however, `getOldPreviewLocations()`
currently does not filter by mimetype and therefore can yield a
non-folder entry which causes an Exception when constructing the Folder
impl.
Filtering for `httpd/unix-directory`, as `getNewPreviewLocations()`
already does, fixes this issue.
Signed-off-by: Dario Mehlich <d.mehlich@gmail.com>
-rw-r--r-- | lib/private/Preview/BackgroundCleanupJob.php | 12 | ||||
-rw-r--r-- | tests/lib/Preview/BackgroundCleanupJobTest.php | 32 |
2 files changed, 39 insertions, 5 deletions
diff --git a/lib/private/Preview/BackgroundCleanupJob.php b/lib/private/Preview/BackgroundCleanupJob.php index a2e91cc2633..fcc411f97dd 100644 --- a/lib/private/Preview/BackgroundCleanupJob.php +++ b/lib/private/Preview/BackgroundCleanupJob.php @@ -89,11 +89,13 @@ class BackgroundCleanupJob extends TimedJob { $qb->expr()->castColumn('a.name', IQueryBuilder::PARAM_INT), 'b.fileid' )) ->where( - $qb->expr()->isNull('b.fileid') - )->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 3b95676e470..33d3a0b7f65 100644 --- a/tests/lib/Preview/BackgroundCleanupJobTest.php +++ b/tests/lib/Preview/BackgroundCleanupJobTest.php @@ -197,13 +197,45 @@ class BackgroundCleanupJobTest extends \Test\TestCase { $f2 = $appdata->newFolder('123456782'); $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(2, 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\''); + } } } |