@@ -203,6 +203,44 @@ function testBackgroundScanOnlyRecurseIncomplete() {
203203 $ this ->assertFalse ($ this ->cache ->getIncomplete ());
204204 }
205205
206+ public function testBackgroundScanNestedIncompleteFolders () {
207+ $ this ->storage ->mkdir ('folder ' );
208+ $ this ->scanner ->backgroundScan ();
209+
210+ $ this ->storage ->mkdir ('folder/subfolder1 ' );
211+ $ this ->storage ->mkdir ('folder/subfolder2 ' );
212+
213+ $ this ->storage ->mkdir ('folder/subfolder1/subfolder3 ' );
214+ $ this ->cache ->put ('folder ' , ['size ' => -1 ]);
215+ $ this ->cache ->put ('folder/subfolder1 ' , ['size ' => -1 ]);
216+
217+ // do a scan to get the folders into the cache.
218+ $ this ->scanner ->backgroundScan ();
219+
220+ $ this ->assertTrue ($ this ->cache ->inCache ('folder/subfolder1/subfolder3 ' ));
221+
222+ $ this ->storage ->file_put_contents ('folder/subfolder1/bar1.txt ' , 'foobar ' );
223+ $ this ->storage ->file_put_contents ('folder/subfolder1/subfolder3/bar3.txt ' , 'foobar ' );
224+ $ this ->storage ->file_put_contents ('folder/subfolder2/bar2.txt ' , 'foobar ' );
225+
226+ //mark folders as incomplete.
227+ $ this ->cache ->put ('folder/subfolder1 ' , ['size ' => -1 ]);
228+ $ this ->cache ->put ('folder/subfolder2 ' , ['size ' => -1 ]);
229+ $ this ->cache ->put ('folder/subfolder1/subfolder3 ' , ['size ' => -1 ]);
230+
231+ $ this ->scanner ->backgroundScan ();
232+
233+ $ this ->assertTrue ($ this ->cache ->inCache ('folder/subfolder1/bar1.txt ' ));
234+ $ this ->assertTrue ($ this ->cache ->inCache ('folder/subfolder2/bar2.txt ' ));
235+ $ this ->assertTrue ($ this ->cache ->inCache ('folder/subfolder1/subfolder3/bar3.txt ' ));
236+
237+ //check if folder sizes are correct.
238+ $ this ->assertEquals (18 , $ this ->cache ->get ('folder ' )['size ' ]);
239+ $ this ->assertEquals (12 , $ this ->cache ->get ('folder/subfolder1 ' )['size ' ]);
240+ $ this ->assertEquals (6 , $ this ->cache ->get ('folder/subfolder1/subfolder3 ' )['size ' ]);
241+ $ this ->assertEquals (6 , $ this ->cache ->get ('folder/subfolder2 ' )['size ' ]);
242+ }
243+
206244 public function testReuseExisting () {
207245 $ this ->fillTestFolders ();
208246
0 commit comments