see_meta.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "io"
  6. "log"
  7. "os"
  8. "github.com/chrislusf/seaweedfs/weed/filer2"
  9. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  10. "github.com/chrislusf/seaweedfs/weed/util"
  11. "github.com/golang/protobuf/proto"
  12. )
  13. var (
  14. metaFile = flag.String("meta", "", "meta file generated via fs.meta.save")
  15. )
  16. func main() {
  17. flag.Parse()
  18. dst, err := os.OpenFile(*metaFile, os.O_RDONLY, 0644)
  19. if err != nil {
  20. log.Fatalf("failed to open %s: %v", *metaFile, err)
  21. }
  22. defer dst.Close()
  23. err = walkMetaFile(dst)
  24. if err != nil {
  25. log.Fatalf("failed to visit %s: %v", *metaFile, err)
  26. }
  27. }
  28. func walkMetaFile(dst *os.File) error {
  29. sizeBuf := make([]byte, 4)
  30. for {
  31. if n, err := dst.Read(sizeBuf); n != 4 {
  32. if err == io.EOF {
  33. return nil
  34. }
  35. return err
  36. }
  37. size := util.BytesToUint32(sizeBuf)
  38. data := make([]byte, int(size))
  39. if n, err := dst.Read(data); n != len(data) {
  40. return err
  41. }
  42. fullEntry := &filer_pb.FullEntry{}
  43. if err := proto.Unmarshal(data, fullEntry); err != nil {
  44. return err
  45. }
  46. fmt.Fprintf(os.Stdout, "file %s %v\n", filer2.FullPath(fullEntry.Dir).Child(fullEntry.Entry.Name), fullEntry.Entry.Attributes.String())
  47. for i, chunk := range fullEntry.Entry.Chunks {
  48. fmt.Fprintf(os.Stdout, " chunk %d %v\n", i+1, chunk.String())
  49. }
  50. }
  51. }