From 6c6b0e2395934ce0d0c01074e53007ce41538e86 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 21 Aug 2016 18:39:17 +0200 Subject: [PATCH 1/2] cat: Add warning when pack was modified --- src/cmds/restic/cmd_cat.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cmds/restic/cmd_cat.go b/src/cmds/restic/cmd_cat.go index 58e5dc452..f4e7eafec 100644 --- a/src/cmds/restic/cmd_cat.go +++ b/src/cmds/restic/cmd_cat.go @@ -157,6 +157,11 @@ 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 From 3af8f530974d2de85418a2d9c2764dd1d83780c3 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 28 Aug 2016 21:23:46 +0200 Subject: [PATCH 2/2] Allow 'cat' for tree blobs --- src/cmds/restic/cmd_cat.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/cmds/restic/cmd_cat.go b/src/cmds/restic/cmd_cat.go index f4e7eafec..959dfabd3 100644 --- a/src/cmds/restic/cmd_cat.go +++ b/src/cmds/restic/cmd_cat.go @@ -166,20 +166,24 @@ func (cmd CmdCat) Execute(args []string) error { 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())