@@ -243,18 +243,22 @@ func (t *Tree) Scan(path string, action EventAction, isDir bool) error {
243243 case ActionMoveFrom :
244244 t .log .Debug ().Str ("path" , path ).Bool ("isDir" , isDir ).Msg ("scanning path (ActionMoveFrom)" )
245245 // 6. file/directory moved out of the watched directory
246- // -> update directory
247- err := t .HandleFileDelete (path )
248- if err != nil {
249- t .log .Error ().Err (err ).Str ("path" , path ).Bool ("isDir" , isDir ).Msg ("failed to handle deleted item" )
246+ // -> remove from caches
247+
248+ // remember the id of the moved away item
249+ spaceID , nodeID , err := t .lookup .IDsForPath (context .Background (), path )
250+ if err == nil {
251+ err = t .lookup .IDHistoryCache .Set (context .Background (), spaceID , nodeID , path )
252+ if err != nil {
253+ t .log .Error ().Err (err ).Str ("path" , path ).Msg ("failed to cache the id of the moved item" )
254+ }
250255 }
251- err = t .setDirty (filepath .Dir (path ), true )
256+
257+ err = t .HandleFileDelete (path )
252258 if err != nil {
253- t .log .Error ().Err (err ).Str ("path" , path ).Bool ("isDir" , isDir ).Msg ("failed to mark directory as dirty " )
259+ t .log .Error ().Err (err ).Str ("path" , path ).Bool ("isDir" , isDir ).Msg ("failed to handle moved away item " )
254260 }
255261
256- go func () { _ = t .WarmupIDCache (filepath .Dir (path ), false , true ) }()
257-
258262 case ActionDelete :
259263 t .log .Debug ().Str ("path" , path ).Bool ("isDir" , isDir ).Msg ("handling deleted item" )
260264
@@ -358,6 +362,7 @@ func (t *Tree) findSpaceId(path string) (string, node.Attributes, error) {
358362}
359363
360364func (t * Tree ) assimilate (item scanItem ) error {
365+ t .log .Debug ().Str ("path" , item .Path ).Bool ("rescan" , item .ForceRescan ).Bool ("recurse" , item .Recurse ).Msg ("assimilate" )
361366 var err error
362367
363368 // First find the space id
@@ -411,7 +416,7 @@ func (t *Tree) assimilate(item scanItem) error {
411416 }
412417
413418 // was it moved or copied/restored with a clashing id?
414- if ok && len (previousParentID ) > 0 && previousPath != item .Path {
419+ if ok && len (parentID ) > 0 && previousPath != item .Path {
415420 _ , err := os .Stat (previousPath )
416421 if err == nil {
417422 // this id clashes with an existing item -> clear metadata and re-assimilate
@@ -451,21 +456,21 @@ func (t *Tree) assimilate(item scanItem) error {
451456 }()
452457 }
453458
454- parentID := attrs .String (prefixes .ParentidAttr )
459+ newParentID := attrs .String (prefixes .ParentidAttr )
455460 if len (parentID ) > 0 {
456461 ref := & provider.Reference {
457462 ResourceId : & provider.ResourceId {
458463 StorageId : t .options .MountID ,
459464 SpaceId : spaceID ,
460- OpaqueId : parentID ,
465+ OpaqueId : newParentID ,
461466 },
462467 Path : filepath .Base (item .Path ),
463468 }
464469 oldRef := & provider.Reference {
465470 ResourceId : & provider.ResourceId {
466471 StorageId : t .options .MountID ,
467472 SpaceId : spaceID ,
468- OpaqueId : string (previousParentID ),
473+ OpaqueId : string (parentID ),
469474 },
470475 Path : filepath .Base (previousPath ),
471476 }
0 commit comments