From c82d42f93e09c6ef8223b7fe0f210f5f0daea6e6 Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Mon, 12 Jan 2026 13:24:47 +0100 Subject: [PATCH] fix(watchfs): Don't cache old id if a copy is detected Even when a copy was detected we added the new item with the old ID to the cache, which triggered a re-assimilation and an ID change on the original file in the end. This should fix it. Partial: #482 --- pkg/storage/fs/posix/tree/assimilation.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/storage/fs/posix/tree/assimilation.go b/pkg/storage/fs/posix/tree/assimilation.go index dbd71237b6c..4d285de8bd1 100644 --- a/pkg/storage/fs/posix/tree/assimilation.go +++ b/pkg/storage/fs/posix/tree/assimilation.go @@ -909,17 +909,24 @@ func (t *Tree) WarmupIDCache(root string, assimilate, onlyDirty bool) error { } if id != "" { - // Check if the item on the previous still exists. In this case it might have been a copy with extended attributes -> set new ID + // Check if the item on the previous path still exists. In this case it might have been a copy with extended attributes -> set new ID + isCopy := false previousPath, ok := t.lookup.GetCachedID(context.Background(), spaceID, id) if ok && previousPath != path { - // this id clashes with an existing id -> re-assimilate _, err := os.Stat(previousPath) if err == nil { - _ = t.assimilate(scanItem{Path: path}) + // previous path (using the same id) still exists -> this is a copy + isCopy = true } } - if err := t.lookup.CacheID(context.Background(), spaceID, id, path); err != nil { - t.log.Error().Err(err).Str("spaceID", spaceID).Str("id", id).Str("path", path).Msg("could not cache id") + if isCopy { + // copy detected -> re-assimilate + _ = t.assimilate(scanItem{Path: path}) + } else { + // update cached id with new path + if err := t.lookup.CacheID(context.Background(), spaceID, id, path); err != nil { + t.log.Error().Err(err).Str("spaceID", spaceID).Str("id", id).Str("path", path).Msg("could not cache id") + } } } } else if assimilate {