diff options
| author | Feng Shao <88640691+shaofeng66@users.noreply.github.com> | 2025-11-18 23:45:12 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-18 07:45:12 -0800 |
| commit | 0299e78de7c7f7e19d5b206b384d0331609e15aa (patch) | |
| tree | 1c71b1399e5ec88e11e399bee826fd7c9d9d5855 /weed/shell/command_fs_meta_load.go | |
| parent | 156ce42f2671f653f87aecedb6bb716f736913af (diff) | |
| download | seaweedfs-0299e78de7c7f7e19d5b206b384d0331609e15aa.tar.xz seaweedfs-0299e78de7c7f7e19d5b206b384d0331609e15aa.zip | |
de/compress the fs meta file if filename ends with gz/gzip (#7500)
* de/compress the fs meta file if filename ends with gz/gzip
* gemini code review
* update help msg
Diffstat (limited to 'weed/shell/command_fs_meta_load.go')
| -rw-r--r-- | weed/shell/command_fs_meta_load.go | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/weed/shell/command_fs_meta_load.go b/weed/shell/command_fs_meta_load.go index f43574f49..c2e01dfc2 100644 --- a/weed/shell/command_fs_meta_load.go +++ b/weed/shell/command_fs_meta_load.go @@ -1,6 +1,7 @@ package shell import ( + "compress/gzip" "context" "flag" "fmt" @@ -60,11 +61,31 @@ func (c *commandFsMetaLoad) Do(args []string, commandEnv *CommandEnv, writer io. return nil } - dst, err := os.OpenFile(fileName, os.O_RDONLY, 0644) + var dst io.Reader + + f, err := os.OpenFile(fileName, os.O_RDONLY, 0644) if err != nil { - return nil + return fmt.Errorf("failed to open file %s: %v", fileName, err) + } + defer f.Close() + + dst = f + + if strings.HasSuffix(fileName, ".gz") || strings.HasSuffix(fileName, ".gzip") { + var gr *gzip.Reader + gr, err = gzip.NewReader(dst) + if err != nil { + return err + } + defer func() { + err1 := gr.Close() + if err == nil { + err = err1 + } + }() + + dst = gr } - defer dst.Close() var dirCount, fileCount uint64 lastLogTime := time.Now() |
