From b866907461c36bd09f0ddce0824b6018ca57f281 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Fri, 26 Dec 2025 12:30:30 -0800 Subject: [PATCH] fs.meta.save: fix directory entry parent path in FullEntry construction (#7886) * Checkpoint from VS Code for coding agent session * Fix fs.meta.save to correctly save directory's own metadata Co-authored-by: chrislusf <1543151+chrislusf@users.noreply.github.com> * address error --------- Co-authored-by: Chris Lu Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: chrislusf <1543151+chrislusf@users.noreply.github.com> --- weed/shell/command_fs_meta_save.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/weed/shell/command_fs_meta_save.go b/weed/shell/command_fs_meta_save.go index ce982820d..377c5e12e 100644 --- a/weed/shell/command_fs_meta_save.go +++ b/weed/shell/command_fs_meta_save.go @@ -2,6 +2,8 @@ package shell import ( "compress/gzip" + "context" + "errors" "flag" "fmt" "io" @@ -146,6 +148,29 @@ func doTraverseBfsAndSaving(filerClient filer_pb.FilerClient, writer io.Writer, var dirCount, fileCount uint64 + // also save the directory itself (path) if it exists in the filer + if e, getErr := filer_pb.GetEntry(context.Background(), filerClient, util.FullPath(path)); getErr != nil { + // Entry not found is expected and can be ignored; log other errors. + if !errors.Is(getErr, filer_pb.ErrNotFound) { + fmt.Fprintf(writer, "failed to get entry %s: %v\n", path, getErr) + } + } else if e != nil { + parentDir, _ := util.FullPath(path).DirAndName() + protoMessage := &filer_pb.FullEntry{ + Dir: parentDir, + Entry: e, + } + if genErr := genFn(protoMessage, outputChan); genErr != nil { + fmt.Fprintf(writer, "marshall error: %v\n", genErr) + } else { + if e.IsDirectory { + atomic.AddUint64(&dirCount, 1) + } else { + atomic.AddUint64(&fileCount, 1) + } + } + } + err := filer_pb.TraverseBfs(filerClient, util.FullPath(path), func(parentPath util.FullPath, entry *filer_pb.Entry) { if strings.HasPrefix(string(parentPath), filer.SystemLogDir) {