Merge pull request #595 from restic/fix-cat

Fix the cat command
This commit is contained in:
Alexander Neumann 2016-08-28 22:28:25 +02:00
commit 6f5bf45212

View file

@ -157,24 +157,33 @@ func (cmd CmdCat) Execute(args []string) error {
return err return err
} }
hash := backend.Hash(buf)
if !hash.Equal(id) {
fmt.Fprintf(cmd.global.stderr, "Warning: hash of data does not match ID, want\n %v\ngot:\n %v\n", id.String(), hash.String())
}
_, err = os.Stdout.Write(buf) _, err = os.Stdout.Write(buf)
return err return err
case "blob": case "blob":
list, err := repo.Index().Lookup(id, pack.Data) for _, t := range []pack.BlobType{pack.Data, pack.Tree} {
if err != nil { list, err := repo.Index().Lookup(id, t)
return err if err != nil {
} continue
blob := list[0] }
blob := list[0]
buf := make([]byte, blob.Length) buf := make([]byte, blob.Length)
data, err := repo.LoadBlob(id, pack.Data, buf) data, err := repo.LoadBlob(id, t, buf)
if err != nil { if err != nil {
return err
}
_, err = os.Stdout.Write(data)
return err return err
} }
_, err = os.Stdout.Write(data) return errors.New("blob not found")
return err
case "tree": case "tree":
debug.Log("cat", "cat tree %v", id.Str()) debug.Log("cat", "cat tree %v", id.Str())