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.

70 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. input := findInputDirectory(args)
  25. filerServer, filerPort, path, err := commandEnv.parseUrl(input)
  26. if err != nil {
  27. return err
  28. }
  29. dir, name := util.FullPath(path).DirAndName()
  30. return commandEnv.withFilerClient(filerServer, filerPort, func(client filer_pb.SeaweedFilerClient) error {
  31. request := &filer_pb.LookupDirectoryEntryRequest{
  32. Name: name,
  33. Directory: dir,
  34. }
  35. respLookupEntry, err := filer_pb.LookupEntry(client, request)
  36. if err != nil {
  37. return err
  38. }
  39. m := jsonpb.Marshaler{
  40. EmitDefaults: true,
  41. Indent: " ",
  42. }
  43. text, marshalErr := m.MarshalToString(respLookupEntry.Entry)
  44. if marshalErr != nil {
  45. return fmt.Errorf("marshal meta: %v", marshalErr)
  46. }
  47. fmt.Fprintf(writer, "%s\n", text)
  48. return nil
  49. })
  50. }