You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.3 KiB

5 years ago
5 years ago
  1. package shell
  2. import (
  3. "fmt"
  4. "io"
  5. "github.com/golang/protobuf/jsonpb"
  6. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  7. "github.com/chrislusf/seaweedfs/weed/util"
  8. )
  9. func init() {
  10. Commands = append(Commands, &commandFsMetaCat{})
  11. }
  12. type commandFsMetaCat struct {
  13. }
  14. func (c *commandFsMetaCat) Name() string {
  15. return "fs.meta.cat"
  16. }
  17. func (c *commandFsMetaCat) Help() string {
  18. return `print out the meta data content for a file or directory
  19. fs.meta.cat /dir/
  20. fs.meta.cat /dir/file_name
  21. `
  22. }
  23. func (c *commandFsMetaCat) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  24. path, err := commandEnv.parseUrl(findInputDirectory(args))
  25. if err != nil {
  26. return err
  27. }
  28. dir, name := util.FullPath(path).DirAndName()
  29. return commandEnv.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
  30. request := &filer_pb.LookupDirectoryEntryRequest{
  31. Name: name,
  32. Directory: dir,
  33. }
  34. respLookupEntry, err := filer_pb.LookupEntry(client, request)
  35. if err != nil {
  36. return err
  37. }
  38. m := jsonpb.Marshaler{
  39. EmitDefaults: true,
  40. Indent: " ",
  41. }
  42. text, marshalErr := m.MarshalToString(respLookupEntry.Entry)
  43. if marshalErr != nil {
  44. return fmt.Errorf("marshal meta: %v", marshalErr)
  45. }
  46. fmt.Fprintf(writer, "%s\n", text)
  47. return nil
  48. })
  49. }