2019-12-21 00:22:18 +08:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-08-18 03:42:03 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
2022-08-18 03:05:07 +08:00
|
|
|
"google.golang.org/protobuf/proto"
|
2019-12-21 00:22:18 +08:00
|
|
|
"io"
|
2023-01-13 12:29:07 +08:00
|
|
|
"sort"
|
2019-12-21 00:22:18 +08:00
|
|
|
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
2019-12-21 00:22:18 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
Commands = append(Commands, &commandFsMetaCat{})
|
|
|
|
}
|
|
|
|
|
|
|
|
type commandFsMetaCat struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandFsMetaCat) Name() string {
|
|
|
|
return "fs.meta.cat"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandFsMetaCat) Help() string {
|
|
|
|
return `print out the meta data content for a file or directory
|
|
|
|
|
|
|
|
fs.meta.cat /dir/
|
|
|
|
fs.meta.cat /dir/file_name
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
2024-09-29 11:22:57 +08:00
|
|
|
func (c *commandFsMetaCat) IsResourceHeavy() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-12-21 00:22:18 +08:00
|
|
|
func (c *commandFsMetaCat) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
|
|
|
|
2020-03-24 12:26:15 +08:00
|
|
|
path, err := commandEnv.parseUrl(findInputDirectory(args))
|
2019-12-21 00:22:18 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-03-23 15:01:34 +08:00
|
|
|
dir, name := util.FullPath(path).DirAndName()
|
2019-12-21 00:22:18 +08:00
|
|
|
|
2021-12-26 16:15:03 +08:00
|
|
|
return commandEnv.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
|
2019-12-21 00:22:18 +08:00
|
|
|
|
|
|
|
request := &filer_pb.LookupDirectoryEntryRequest{
|
|
|
|
Name: name,
|
|
|
|
Directory: dir,
|
|
|
|
}
|
2020-03-08 08:51:46 +08:00
|
|
|
respLookupEntry, err := filer_pb.LookupEntry(client, request)
|
2019-12-21 00:22:18 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-01-13 12:29:07 +08:00
|
|
|
chunks := respLookupEntry.Entry.Chunks
|
|
|
|
sort.Slice(chunks, func(i, j int) bool {
|
|
|
|
return chunks[i].Offset < chunks[j].Offset
|
|
|
|
})
|
|
|
|
|
2022-08-18 03:42:03 +08:00
|
|
|
filer.ProtoToText(writer, respLookupEntry.Entry)
|
2019-12-21 00:22:18 +08:00
|
|
|
|
2020-09-04 02:00:20 +08:00
|
|
|
bytes, _ := proto.Marshal(respLookupEntry.Entry)
|
|
|
|
gzippedBytes, _ := util.GzipData(bytes)
|
2020-11-22 05:06:35 +08:00
|
|
|
// zstdBytes, _ := util.ZstdData(bytes)
|
2022-11-15 22:33:36 +08:00
|
|
|
// fmt.Fprintf(writer, "chunks %d meta size: %d gzip:%d zstd:%d\n", len(respLookupEntry.Entry.GetChunks()), len(bytes), len(gzippedBytes), len(zstdBytes))
|
|
|
|
fmt.Fprintf(writer, "chunks %d meta size: %d gzip:%d\n", len(respLookupEntry.Entry.GetChunks()), len(bytes), len(gzippedBytes))
|
2020-09-04 00:51:21 +08:00
|
|
|
|
2019-12-21 00:22:18 +08:00
|
|
|
return nil
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|