From 41f59ffc780d2e8085adf20764c03803a12d7355 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Mon, 30 Jan 2017 10:48:21 +0100 Subject: [PATCH 1/4] Fix 'cat' command for tree blobs --- src/cmds/restic/cmd_cat.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmds/restic/cmd_cat.go b/src/cmds/restic/cmd_cat.go index 47a7e06a2..8b4015306 100644 --- a/src/cmds/restic/cmd_cat.go +++ b/src/cmds/restic/cmd_cat.go @@ -172,7 +172,7 @@ func runCat(gopts GlobalOptions, args []string) error { blob := list[0] buf := make([]byte, blob.Length) - n, err := repo.LoadBlob(restic.DataBlob, id, buf) + n, err := repo.LoadBlob(t, id, buf) if err != nil { return err } From 524ce01423af849cfec7d1961d778f9db43b4fbd Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Mon, 30 Jan 2017 10:48:50 +0100 Subject: [PATCH 2/4] Remove 'cat tree' command --- src/cmds/restic/cmd_cat.go | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/cmds/restic/cmd_cat.go b/src/cmds/restic/cmd_cat.go index 8b4015306..932d77d5d 100644 --- a/src/cmds/restic/cmd_cat.go +++ b/src/cmds/restic/cmd_cat.go @@ -9,7 +9,6 @@ import ( "restic" "restic/backend" - "restic/debug" "restic/errors" "restic/repository" ) @@ -184,23 +183,6 @@ func runCat(gopts GlobalOptions, args []string) error { return errors.Fatal("blob not found") - case "tree": - debug.Log("cat tree %v", id.Str()) - tree, err := repo.LoadTree(id) - if err != nil { - debug.Log("unable to load tree %v: %v", id.Str(), err) - return err - } - - buf, err := json.MarshalIndent(&tree, "", " ") - if err != nil { - debug.Log("error json.MarshalIndent(): %v", err) - return err - } - - _, err = os.Stdout.Write(append(buf, '\n')) - return nil - default: return errors.Fatal("invalid type") } From 658bee17e975b64964f1524bf241021760c9a2e2 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Mon, 30 Jan 2017 10:48:59 +0100 Subject: [PATCH 3/4] Clean up documentation, remove inconsistencies --- doc/Design.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/doc/Design.md b/doc/Design.md index 6e9cd39af..117554d2b 100644 --- a/doc/Design.md +++ b/doc/Design.md @@ -327,10 +327,11 @@ A snapshot references a tree by the SHA-256 hash of the JSON string representation of its contents. Trees and data are saved in pack files in a subdirectory of the directory `data`. -The command `restic cat tree` can be used to inspect the tree referenced above: +The command `restic cat blob` can be used to inspect the tree referenced above +(piping the output of the command to `jq .` so that the JSON is indented): ```console -$ restic -r /tmp/restic-repo cat tree b8138ab08a4722596ac89c917827358da4672eac68e3c03a8115b88dbf4bfb59 +$ restic -r /tmp/restic-repo cat blob b8138ab08a4722596ac89c917827358da4672eac68e3c03a8115b88dbf4bfb59 | jq . enter password for repository: { "nodes": [ @@ -356,11 +357,11 @@ A tree contains a list of entries (in the field `nodes`) which contain meta data like a name and timestamps. When the entry references a directory, the field `subtree` contains the plain text ID of another tree object. -When the command `restic cat tree` is used, the storage hash is needed to print +When the command `restic cat blob` is used, the plaintext ID is needed to print a tree. The tree referenced above can be dumped as follows: ```console -$ restic -r /tmp/restic-repo cat tree 8b238c8811cc362693e91a857460c78d3acf7d9edb2f111048691976803cf16e +$ restic -r /tmp/restic-repo cat blob 8b238c8811cc362693e91a857460c78d3acf7d9edb2f111048691976803cf16e enter password for repository: { "nodes": [ @@ -389,8 +390,8 @@ enter password for repository: This tree contains a file entry. This time, the `subtree` field is not present and the `content` field contains a list with one plain text SHA-256 hash. -The command `restic cat data` can be used to extract and decrypt data given a -plaintext ID, e.g. for the data mentioned above: +The command `restic cat blob` can also be used to extract and decrypt data +given a plaintext ID, e.g. for the data mentioned above: ```console $ restic -r /tmp/restic-repo cat blob 50f77b3b4291e8411a027b9f9b9e64658181cc676ce6ba9958b95f268cb1109d | sha256sum From 44f4ff9d37c06be41eeb32bcd9d1822f026f5688 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Mon, 30 Jan 2017 10:50:52 +0100 Subject: [PATCH 4/4] Remove 'tree' from help text for 'cat' command --- src/cmds/restic/cmd_cat.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmds/restic/cmd_cat.go b/src/cmds/restic/cmd_cat.go index 932d77d5d..74f04200d 100644 --- a/src/cmds/restic/cmd_cat.go +++ b/src/cmds/restic/cmd_cat.go @@ -14,7 +14,7 @@ import ( ) var cmdCat = &cobra.Command{ - Use: "cat [flags] [pack|blob|tree|snapshot|key|masterkey|config|lock] ID", + Use: "cat [flags] [pack|blob|snapshot|key|masterkey|config|lock] ID", Short: "print internal objects to stdout", Long: ` The "cat" command is used to print internal objects to stdout.