Merge pull request #761 from restic/fix-758

Remove inconsistencies regarding the `cat` command
This commit is contained in:
Alexander Neumann 2017-01-30 18:25:49 +01:00
commit 7d49c65dd0
2 changed files with 9 additions and 26 deletions

View File

@ -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 representation of its contents. Trees and data are saved in pack files in a
subdirectory of the directory `data`. 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 ```console
$ restic -r /tmp/restic-repo cat tree b8138ab08a4722596ac89c917827358da4672eac68e3c03a8115b88dbf4bfb59 $ restic -r /tmp/restic-repo cat blob b8138ab08a4722596ac89c917827358da4672eac68e3c03a8115b88dbf4bfb59 | jq .
enter password for repository: enter password for repository:
{ {
"nodes": [ "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 data like a name and timestamps. When the entry references a directory, the
field `subtree` contains the plain text ID of another tree object. 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: a tree. The tree referenced above can be dumped as follows:
```console ```console
$ restic -r /tmp/restic-repo cat tree 8b238c8811cc362693e91a857460c78d3acf7d9edb2f111048691976803cf16e $ restic -r /tmp/restic-repo cat blob 8b238c8811cc362693e91a857460c78d3acf7d9edb2f111048691976803cf16e
enter password for repository: enter password for repository:
{ {
"nodes": [ "nodes": [
@ -389,8 +390,8 @@ enter password for repository:
This tree contains a file entry. This time, the `subtree` field is not present 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. 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 The command `restic cat blob` can also be used to extract and decrypt data
plaintext ID, e.g. for the data mentioned above: given a plaintext ID, e.g. for the data mentioned above:
```console ```console
$ restic -r /tmp/restic-repo cat blob 50f77b3b4291e8411a027b9f9b9e64658181cc676ce6ba9958b95f268cb1109d | sha256sum $ restic -r /tmp/restic-repo cat blob 50f77b3b4291e8411a027b9f9b9e64658181cc676ce6ba9958b95f268cb1109d | sha256sum

View File

@ -9,13 +9,12 @@ import (
"restic" "restic"
"restic/backend" "restic/backend"
"restic/debug"
"restic/errors" "restic/errors"
"restic/repository" "restic/repository"
) )
var cmdCat = &cobra.Command{ 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", Short: "print internal objects to stdout",
Long: ` Long: `
The "cat" command is used to print internal objects to stdout. The "cat" command is used to print internal objects to stdout.
@ -172,7 +171,7 @@ func runCat(gopts GlobalOptions, args []string) error {
blob := list[0] blob := list[0]
buf := make([]byte, blob.Length) buf := make([]byte, blob.Length)
n, err := repo.LoadBlob(restic.DataBlob, id, buf) n, err := repo.LoadBlob(t, id, buf)
if err != nil { if err != nil {
return err return err
} }
@ -184,23 +183,6 @@ func runCat(gopts GlobalOptions, args []string) error {
return errors.Fatal("blob not found") 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: default:
return errors.Fatal("invalid type") return errors.Fatal("invalid type")
} }