2019-12-21 00:22:18 +08:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
2020-08-23 15:00:36 +08:00
|
|
|
"sort"
|
2019-12-21 00:22:18 +08:00
|
|
|
|
|
|
|
"github.com/golang/protobuf/jsonpb"
|
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
2020-03-23 15:01:34 +08:00
|
|
|
"github.com/chrislusf/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
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-03-24 12:26:15 +08:00
|
|
|
return commandEnv.WithFilerClient(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
|
|
|
|
}
|
|
|
|
|
|
|
|
m := jsonpb.Marshaler{
|
|
|
|
EmitDefaults: true,
|
|
|
|
Indent: " ",
|
|
|
|
}
|
|
|
|
|
2020-08-23 15:00:36 +08:00
|
|
|
sort.Slice(respLookupEntry.Entry.Chunks, func(i, j int) bool {
|
|
|
|
if respLookupEntry.Entry.Chunks[i].Offset == respLookupEntry.Entry.Chunks[j].Offset {
|
|
|
|
return respLookupEntry.Entry.Chunks[i].Mtime < respLookupEntry.Entry.Chunks[j].Mtime
|
|
|
|
}
|
|
|
|
return respLookupEntry.Entry.Chunks[i].Offset < respLookupEntry.Entry.Chunks[j].Offset
|
|
|
|
})
|
|
|
|
|
2019-12-21 00:22:18 +08:00
|
|
|
text, marshalErr := m.MarshalToString(respLookupEntry.Entry)
|
|
|
|
if marshalErr != nil {
|
|
|
|
return fmt.Errorf("marshal meta: %v", marshalErr)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(writer, "%s\n", text)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|