From ed8c91ab19c5664c7c652bc44abaebd5acc61cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Thu, 7 Nov 2024 08:28:34 +0100 Subject: [PATCH] Handle MovedFrom events --- pkg/storage/fs/posix/tree/assimilation.go | 12 +++++++++++- pkg/storage/fs/posix/tree/gpfswatchfolderwatcher.go | 3 +++ pkg/storage/fs/posix/tree/inotifywatcher.go | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/storage/fs/posix/tree/assimilation.go b/pkg/storage/fs/posix/tree/assimilation.go index e4763ad950..2cc3fcf95d 100644 --- a/pkg/storage/fs/posix/tree/assimilation.go +++ b/pkg/storage/fs/posix/tree/assimilation.go @@ -59,6 +59,7 @@ const ( ActionUpdate ActionMove ActionDelete + ActionMoveFrom ) type queueItem struct { @@ -222,9 +223,18 @@ func (t *Tree) Scan(path string, action EventAction, isDir bool) error { Recurse: isDir, }) + case ActionMoveFrom: + // 6. file/directory moved out of the watched directory + // -> update directory + if err := t.setDirty(filepath.Dir(path), true); err != nil { + return err + } + + go func() { _ = t.WarmupIDCache(filepath.Dir(path), false, true) }() + case ActionDelete: _ = t.HandleFileDelete(path) - // 6. Deleted file or directory + // 7. Deleted file or directory // -> update parent and all children if err := t.setDirty(filepath.Dir(path), true); err != nil { return err diff --git a/pkg/storage/fs/posix/tree/gpfswatchfolderwatcher.go b/pkg/storage/fs/posix/tree/gpfswatchfolderwatcher.go index 3fafebc656..378185fa21 100644 --- a/pkg/storage/fs/posix/tree/gpfswatchfolderwatcher.go +++ b/pkg/storage/fs/posix/tree/gpfswatchfolderwatcher.go @@ -54,6 +54,9 @@ func (w *GpfsWatchFolderWatcher) Watch(topic string) { case strings.Contains(lwev.Event, "IN_DELETE"): _ = w.tree.Scan(lwev.Path, ActionDelete, isDir) + case strings.Contains(lwev.Event, "IN_MOVE_FROM"): + _ = w.tree.Scan(lwev.Path, ActionMoveFrom, isDir) + case strings.Contains(lwev.Event, "IN_CREATE"): _ = w.tree.Scan(lwev.Path, ActionCreate, isDir) diff --git a/pkg/storage/fs/posix/tree/inotifywatcher.go b/pkg/storage/fs/posix/tree/inotifywatcher.go index b5e5d8f02b..65c38aaf2d 100644 --- a/pkg/storage/fs/posix/tree/inotifywatcher.go +++ b/pkg/storage/fs/posix/tree/inotifywatcher.go @@ -30,6 +30,7 @@ func (iw *InotifyWatcher) Watch(path string) { Events: []inotifywaitgo.EVENT{ inotifywaitgo.CREATE, inotifywaitgo.MOVED_TO, + inotifywaitgo.MOVED_FROM, inotifywaitgo.CLOSE_WRITE, inotifywaitgo.DELETE, }, @@ -50,6 +51,8 @@ func (iw *InotifyWatcher) Watch(path string) { switch e { case inotifywaitgo.DELETE: _ = iw.tree.Scan(event.Filename, ActionDelete, event.IsDir) + case inotifywaitgo.MOVED_FROM: + _ = iw.tree.Scan(event.Filename, ActionMoveFrom, event.IsDir) case inotifywaitgo.CREATE: case inotifywaitgo.MOVED_TO: _ = iw.tree.Scan(event.Filename, ActionCreate, event.IsDir)