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.

74 lines
1.7 KiB

3 months ago
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. "sort"
  8. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  9. "github.com/seaweedfs/seaweedfs/weed/util"
  10. )
  11. func init() {
  12. Commands = append(Commands, &commandFsMetaCat{})
  13. }
  14. type commandFsMetaCat struct {
  15. }
  16. func (c *commandFsMetaCat) Name() string {
  17. return "fs.meta.cat"
  18. }
  19. func (c *commandFsMetaCat) Help() string {
  20. return `print out the meta data content for a file or directory
  21. fs.meta.cat /dir/
  22. fs.meta.cat /dir/file_name
  23. `
  24. }
  25. func (c *commandFsMetaCat) HasTag(CommandTag) bool {
  26. return false
  27. }
  28. func (c *commandFsMetaCat) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  29. path, err := commandEnv.parseUrl(findInputDirectory(args))
  30. if err != nil {
  31. return err
  32. }
  33. dir, name := util.FullPath(path).DirAndName()
  34. return commandEnv.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
  35. request := &filer_pb.LookupDirectoryEntryRequest{
  36. Name: name,
  37. Directory: dir,
  38. }
  39. respLookupEntry, err := filer_pb.LookupEntry(client, request)
  40. if err != nil {
  41. return err
  42. }
  43. chunks := respLookupEntry.Entry.Chunks
  44. sort.Slice(chunks, func(i, j int) bool {
  45. return chunks[i].Offset < chunks[j].Offset
  46. })
  47. filer.ProtoToText(writer, respLookupEntry.Entry)
  48. bytes, _ := proto.Marshal(respLookupEntry.Entry)
  49. gzippedBytes, _ := util.GzipData(bytes)
  50. // zstdBytes, _ := util.ZstdData(bytes)
  51. // fmt.Fprintf(writer, "chunks %d meta size: %d gzip:%d zstd:%d\n", len(respLookupEntry.Entry.GetChunks()), len(bytes), len(gzippedBytes), len(zstdBytes))
  52. fmt.Fprintf(writer, "chunks %d meta size: %d gzip:%d\n", len(respLookupEntry.Entry.GetChunks()), len(bytes), len(gzippedBytes))
  53. return nil
  54. })
  55. }