aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDario Mehlich <d.mehlich@gmail.com>2025-01-27 10:16:08 +0100
committerDario Mehlich <d.mehlich@gmail.com>2025-01-27 10:16:08 +0100
commit8c309130cf5cfd9278c63c674a9b9cbe08b9f403 (patch)
tree692cb55236425d1b7be0d466b20acaddf1e6d470 /tests
parent29724ff27e9377f52a5d97a6944523522004e1ce (diff)
downloadnextcloud-server-8c309130cf5cfd9278c63c674a9b9cbe08b9f403.tar.gz
nextcloud-server-8c309130cf5cfd9278c63c674a9b9cbe08b9f403.zip
fix(preview): Filter for folders in cleanup old preview job
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>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Preview/BackgroundCleanupJobTest.php31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/lib/Preview/BackgroundCleanupJobTest.php b/tests/lib/Preview/BackgroundCleanupJobTest.php
index 9c521376af5..945366cde9f 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\'');
+ }
}
}