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.4 KiB

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