1
0
mirror of https://github.com/restic/restic.git synced 2024-06-27 07:55:08 +02:00

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
}
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)
return err
case "blob":
list, err := repo.Index().Lookup(id, pack.Data)
if err != nil {
return err
}
blob := list[0]
for _, t := range []pack.BlobType{pack.Data, pack.Tree} {
list, err := repo.Index().Lookup(id, t)
if err != nil {
continue
}
blob := list[0]
buf := make([]byte, blob.Length)
data, err := repo.LoadBlob(id, pack.Data, buf)
if err != nil {
buf := make([]byte, blob.Length)
data, err := repo.LoadBlob(id, t, buf)
if err != nil {
return err
}
_, err = os.Stdout.Write(data)
return err
}
_, err = os.Stdout.Write(data)
return err
return errors.New("blob not found")
case "tree":
debug.Log("cat", "cat tree %v", id.Str())