aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDario Mehlich <d.mehlich@gmail.com>2025-01-27 10:16:08 +0100
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2025-01-27 15:09:36 +0000
commit654034638e6ec8f1e71b9fa53d03dc5049bfa363 (patch)
tree7a54e9f7293b3f6493c637c6738ebbb906f8a7de
parent458856b2f8ad79908a6bf22189aa186951b728c1 (diff)
downloadnextcloud-server-backport/48581/stable30.tar.gz
nextcloud-server-backport/48581/stable30.zip
fix(preview): Filter for folders in cleanup old preview jobbackport/48581/stable30
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.php14
-rw-r--r--tests/lib/Preview/BackgroundCleanupJobTest.php31
2 files changed, 38 insertions, 7 deletions
diff --git a/lib/private/Preview/BackgroundCleanupJob.php b/lib/private/Preview/BackgroundCleanupJob.php
index 319a9d4804f..85fe8d3303e 100644
--- a/lib/private/Preview/BackgroundCleanupJob.php
+++ b/lib/private/Preview/BackgroundCleanupJob.php
@@ -77,13 +77,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.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 82f19797728..0aad3121a7b 100644
--- a/tests/lib/Preview/BackgroundCleanupJobTest.php
+++ b/tests/lib/Preview/BackgroundCleanupJobTest.php
@@ -191,13 +191,44 @@ class BackgroundCleanupJobTest extends \Test\TestCase {
$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\'');
+ }
}
}