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.

64 lines
1.5 KiB

5 years ago
  1. package shell
  2. import (
  3. "fmt"
  4. "github.com/seaweedfs/seaweedfs/weed/filer"
  5. "google.golang.org/protobuf/proto"
  6. "io"
  7. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  8. "github.com/seaweedfs/seaweedfs/weed/util"
  9. )
  10. func init() {
  11. Commands = append(Commands, &commandFsMetaCat{})
  12. }
  13. type commandFsMetaCat struct {
  14. }
  15. func (c *commandFsMetaCat) Name() string {
  16. return "fs.meta.cat"
  17. }
  18. func (c *commandFsMetaCat) Help() string {
  19. return `print out the meta data content for a file or directory
  20. fs.meta.cat /dir/
  21. fs.meta.cat /dir/file_name
  22. `
  23. }
  24. func (c *commandFsMetaCat) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  25. path, err := commandEnv.parseUrl(findInputDirectory(args))
  26. if err != nil {
  27. return err
  28. }
  29. dir, name := util.FullPath(path).DirAndName()
  30. return commandEnv.WithFilerClient(false, 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. filer.ProtoToText(writer, respLookupEntry.Entry)
  40. bytes, _ := proto.Marshal(respLookupEntry.Entry)
  41. gzippedBytes, _ := util.GzipData(bytes)
  42. // zstdBytes, _ := util.ZstdData(bytes)
  43. // fmt.Fprintf(writer, "chunks %d meta size: %d gzip:%d zstd:%d\n", len(respLookupEntry.Entry.Chunks), len(bytes), len(gzippedBytes), len(zstdBytes))
  44. fmt.Fprintf(writer, "chunks %d meta size: %d gzip:%d\n", len(respLookupEntry.Entry.Chunks), len(bytes), len(gzippedBytes))
  45. return nil
  46. })
  47. }