@@ -253,6 +253,48 @@ public function testMoveCrossStorage(): void {
253253 $ this ->assertEquals ($ cached ['fileid ' ], $ cachedTarget ['fileid ' ]);
254254 }
255255
256+ public function testMoveCrossStorageMissingTargetParent (): void {
257+ $ storage2 = new Temporary ([]);
258+ $ cache2 = $ storage2 ->getCache ();
259+ Filesystem::mount ($ storage2 , [], '/bar ' );
260+ $ this ->storage ->file_put_contents ('foo.txt ' , 'qwerty ' );
261+ $ this ->updater ->update ('foo.txt ' );
262+ $ cached = $ this ->cache ->get ('foo.txt ' );
263+
264+ // the target parent exists on disk but is missing from the cache
265+ $ storage2 ->mkdir ('sub ' );
266+ $ this ->assertFalse ($ cache2 ->inCache ('sub ' ));
267+
268+ $ storage2 ->moveFromStorage ($ this ->storage , 'foo.txt ' , 'sub/bar.txt ' );
269+ $ storage2 ->getUpdater ()->renameFromStorage ($ this ->storage , 'foo.txt ' , 'sub/bar.txt ' );
270+
271+ $ this ->assertFalse ($ this ->cache ->inCache ('foo.txt ' ));
272+ $ this ->assertTrue ($ cache2 ->inCache ('sub ' ));
273+ $ this ->assertTrue ($ cache2 ->inCache ('sub/bar.txt ' ));
274+
275+ // the moved entry is attached to the scanned parent instead of being orphaned
276+ $ cachedTarget = $ cache2 ->get ('sub/bar.txt ' );
277+ $ this ->assertEquals ($ cache2 ->getId ('sub ' ), $ cachedTarget ['parent ' ]);
278+ $ this ->assertEquals ($ cached ['fileid ' ], $ cachedTarget ['fileid ' ]);
279+ }
280+
281+ public function testMoveCrossStorageSourceNotInCache (): void {
282+ $ storage2 = new Temporary ([]);
283+ $ cache2 = $ storage2 ->getCache ();
284+ Filesystem::mount ($ storage2 , [], '/bar ' );
285+ $ this ->storage ->file_put_contents ('foo.txt ' , 'qwerty ' );
286+ // the source was never scanned into the cache
287+ $ this ->assertFalse ($ this ->cache ->inCache ('foo.txt ' ));
288+
289+ $ storage2 ->moveFromStorage ($ this ->storage , 'foo.txt ' , 'bar.txt ' );
290+ $ storage2 ->getUpdater ()->renameFromStorage ($ this ->storage , 'foo.txt ' , 'bar.txt ' );
291+
292+ // the target still gets a cache entry
293+ $ this ->assertTrue ($ cache2 ->inCache ('bar.txt ' ));
294+ $ cachedTarget = $ cache2 ->get ('bar.txt ' );
295+ $ this ->assertEquals (6 , $ cachedTarget ['size ' ]);
296+ }
297+
256298 public function testMoveFolderCrossStorage (): void {
257299 $ storage2 = new Temporary ([]);
258300 $ cache2 = $ storage2 ->getCache ();
0 commit comments