Skip to content

Commit

Permalink
fix(preview): Filter for folders in cleanup old preview job
Browse files Browse the repository at this point in the history
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 <[email protected]>

[skip ci]
  • Loading branch information
hammer065 authored and AndyScherzinger committed Jan 27, 2025
1 parent 8b46771 commit de2e082
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/lib/Preview/BackgroundCleanupJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,33 @@ public function testOldPreviews() {
$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');
$this->assertSame(2, count($appdata->getDirectoryListing()));

$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\'');
}
}
}

0 comments on commit de2e082

Please sign in to comment.