diff options
author | Jakob Borg <jakob@nym.se> | 2014-04-25 08:28:56 +0200 |
---|---|---|
committer | Jakob Borg <jakob@nym.se> | 2014-04-25 08:28:56 +0200 |
commit | 07d49b61d0ee4d6a43e368a60cb16c5647cd9d4e (patch) | |
tree | 3e6713fe25976ca9b3bbc1c4abfa9f9f42f24b3f /cmd | |
parent | 0c4e6ae7de058ecd998dc6a1a5d6210f2dc35f29 (diff) |
Debug utility to print index filev0.8.2
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/stpidx/main.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/cmd/stpidx/main.go b/cmd/stpidx/main.go new file mode 100644 index 0000000000..b9907d646e --- /dev/null +++ b/cmd/stpidx/main.go @@ -0,0 +1,52 @@ +package main + +import ( + "compress/gzip" + "flag" + "log" + "os" + + "github.com/calmh/syncthing/protocol" +) + +func main() { + log.SetFlags(0) + log.SetOutput(os.Stdout) + + showBlocks := flag.Bool("b", false, "Show blocks") + flag.Parse() + name := flag.Arg(0) + + idxf, err := os.Open(name) + if err != nil { + log.Fatal(err) + } + defer idxf.Close() + + gzr, err := gzip.NewReader(idxf) + if err != nil { + log.Fatal(err) + } + defer gzr.Close() + + var im protocol.IndexMessage + err = im.DecodeXDR(gzr) + if err != nil { + log.Fatal(err) + } + + log.Printf("Repo: %q, Files: %d", im.Repository, len(im.Files)) + for _, file := range im.Files { + del := file.Flags&protocol.FlagDeleted != 0 + inv := file.Flags&protocol.FlagInvalid != 0 + dir := file.Flags&protocol.FlagDirectory != 0 + prm := file.Flags & 0777 + log.Printf("File: %q, Del: %v, Inv: %v, Dir: %v, Perm: 0%03o, Modified: %d, Blocks: %d", + file.Name, del, inv, dir, prm, file.Modified, len(file.Blocks)) + if *showBlocks { + for _, block := range file.Blocks { + log.Printf(" Size: %6d, Hash: %x", block.Size, block.Hash) + } + } + } +} |