Skip to content

Commit de2e082

Browse files
hammer065AndyScherzinger
authored andcommitted
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> [skip ci]
1 parent 8b46771 commit de2e082

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/lib/Preview/BackgroundCleanupJobTest.php

+20
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,33 @@ public function testOldPreviews() {
197197
$f2 = $appdata->newFolder('123456782');
198198
$f2->newFile('foo.jpg', 'foo');
199199

200+
/*
201+
* Cleanup of OldPreviewLocations should only remove numeric folders on AppData level,
202+
* therefore these files should stay untouched.
203+
*/
204+
$appdata->getFolder('/')->newFile('not-a-directory', 'foo');
205+
$appdata->getFolder('/')->newFile('133742', 'bar');
206+
200207
$appdata = \OC::$server->getAppDataDir('preview');
201208
$this->assertSame(2, count($appdata->getDirectoryListing()));
202209

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

206213
$appdata = \OC::$server->getAppDataDir('preview');
214+
215+
// Check if the files created above are still present
216+
// Remember: AppData::getDirectoryListing filters all non-folders
207217
$this->assertSame(0, count($appdata->getDirectoryListing()));
218+
try {
219+
$appdata->getFolder('/')->getFile('not-a-directory');
220+
} catch (NotFoundException) {
221+
$this->fail('Could not find file \'not-a-directory\'');
222+
}
223+
try {
224+
$appdata->getFolder('/')->getFile('133742');
225+
} catch (NotFoundException) {
226+
$this->fail('Could not find file \'133742\'');
227+
}
208228
}
209229
}

0 commit comments

Comments
 (0)