Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

fs.meta.save: fix directory entry parent path in FullEntry construction (#7886)

Copilotb866907461c3
diff --git a/weed/shell/command_fs_meta_save.go b/weed/shell/command_fs_meta_save.go
index ce982820dd..377c5e12e9 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) {