2019-12-20 16:22:18 +00:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-04-18 02:35:43 +00:00
|
|
|
"github.com/golang/protobuf/jsonpb"
|
2020-09-03 16:51:21 +00:00
|
|
|
"github.com/golang/protobuf/proto"
|
2022-04-18 02:35:43 +00:00
|
|
|
"golang.org/x/exp/slices"
|
2019-12-20 16:22:18 +00:00
|
|
|
"io"
|
|
|
|
|
2022-07-29 07:17:28 +00:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
2019-12-20 16:22:18 +00: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
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandFsMetaCat) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
|
|
|
|
2020-03-24 04:26:15 +00:00
|
|
|
path, err := commandEnv.parseUrl(findInputDirectory(args))
|
2019-12-20 16:22:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-03-23 07:01:34 +00:00
|
|
|
dir, name := util.FullPath(path).DirAndName()
|
2019-12-20 16:22:18 +00:00
|
|
|
|
2021-12-26 08:15:03 +00:00
|
|
|
return commandEnv.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
|
2019-12-20 16:22:18 +00:00
|
|
|
|
|
|
|
request := &filer_pb.LookupDirectoryEntryRequest{
|
|
|
|
Name: name,
|
|
|
|
Directory: dir,
|
|
|
|
}
|
2020-03-08 00:51:46 +00:00
|
|
|
respLookupEntry, err := filer_pb.LookupEntry(client, request)
|
2019-12-20 16:22:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
m := jsonpb.Marshaler{
|
|
|
|
EmitDefaults: true,
|
|
|
|
Indent: " ",
|
|
|
|
}
|
2022-04-18 02:35:43 +00:00
|
|
|
slices.SortFunc(respLookupEntry.Entry.Chunks, func(a, b *filer_pb.FileChunk) bool {
|
|
|
|
if a.Offset == b.Offset {
|
|
|
|
return a.Mtime < b.Mtime
|
2020-08-23 07:00:36 +00:00
|
|
|
}
|
2022-04-18 02:35:43 +00:00
|
|
|
return a.Offset < b.Offset
|
2020-08-23 07:00:36 +00:00
|
|
|
})
|
2019-12-20 16:22:18 +00:00
|
|
|
text, marshalErr := m.MarshalToString(respLookupEntry.Entry)
|
|
|
|
if marshalErr != nil {
|
|
|
|
return fmt.Errorf("marshal meta: %v", marshalErr)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(writer, "%s\n", text)
|
|
|
|
|
2020-09-03 18:00:20 +00:00
|
|
|
bytes, _ := proto.Marshal(respLookupEntry.Entry)
|
|
|
|
gzippedBytes, _ := util.GzipData(bytes)
|
2020-11-21 21:06:35 +00:00
|
|
|
// zstdBytes, _ := util.ZstdData(bytes)
|
|
|
|
// fmt.Fprintf(writer, "chunks %d meta size: %d gzip:%d zstd:%d\n", len(respLookupEntry.Entry.Chunks), len(bytes), len(gzippedBytes), len(zstdBytes))
|
|
|
|
fmt.Fprintf(writer, "chunks %d meta size: %d gzip:%d\n", len(respLookupEntry.Entry.Chunks), len(bytes), len(gzippedBytes))
|
2020-09-03 16:51:21 +00:00
|
|
|
|
2019-12-20 16:22:18 +00:00
|
|
|
return nil
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|