@@ -191,13 +191,44 @@ public function testOldPreviews(): void {
191191 $ f2 = $ appdata ->newFolder ((string )PHP_INT_MAX - 1 );
192192 $ f2 ->newFile ('foo.jpg ' , 'foo ' );
193193
194+ /*
195+ * Cleanup of OldPreviewLocations should only remove numeric folders on AppData level,
196+ * therefore these files should stay untouched.
197+ */
198+ $ appdata ->getFolder ('/ ' )->newFile ('not-a-directory ' , 'foo ' );
199+ $ appdata ->getFolder ('/ ' )->newFile ('133742 ' , 'bar ' );
200+
194201 $ appdata = \OC ::$ server ->getAppDataDir ('preview ' );
202+ // AppData::getDirectoryListing filters all non-folders
195203 $ this ->assertSame (3 , count ($ appdata ->getDirectoryListing ()));
204+ try {
205+ $ appdata ->getFolder ('/ ' )->getFile ('not-a-directory ' );
206+ } catch (NotFoundException ) {
207+ $ this ->fail ('Could not find file \'not-a-directory \'' );
208+ }
209+ try {
210+ $ appdata ->getFolder ('/ ' )->getFile ('133742 ' );
211+ } catch (NotFoundException ) {
212+ $ this ->fail ('Could not find file \'133742 \'' );
213+ }
196214
197215 $ job = new BackgroundCleanupJob ($ this ->timeFactory , $ this ->connection , $ this ->getRoot (), $ this ->mimeTypeLoader , true );
198216 $ job ->run ([]);
199217
200218 $ appdata = \OC ::$ server ->getAppDataDir ('preview ' );
219+
220+ // Check if the files created above are still present
221+ // Remember: AppData::getDirectoryListing filters all non-folders
201222 $ this ->assertSame (0 , count ($ appdata ->getDirectoryListing ()));
223+ try {
224+ $ appdata ->getFolder ('/ ' )->getFile ('not-a-directory ' );
225+ } catch (NotFoundException ) {
226+ $ this ->fail ('Could not find file \'not-a-directory \'' );
227+ }
228+ try {
229+ $ appdata ->getFolder ('/ ' )->getFile ('133742 ' );
230+ } catch (NotFoundException ) {
231+ $ this ->fail ('Could not find file \'133742 \'' );
232+ }
202233 }
203234}
0 commit comments