From a858ab254b4e29aead0ba97e9bbf5cb8df788e3e Mon Sep 17 00:00:00 2001 From: Daniel Danner Date: Wed, 11 Oct 2023 20:35:43 +0200 Subject: [PATCH] Include inode in JSON output for find and ls This introduces the inode attribute to the JSON output emitted for nodes in `ls` and matches in `find`. There doesn't seem to be any discernible reason to omit the inode and it can be useful in scripting scenarios. --- changelog/unreleased/pull-4511 | 7 +++++++ cmd/restic/cmd_find.go | 1 - cmd/restic/cmd_ls.go | 2 ++ doc/075_scripting.rst | 4 ++++ 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/pull-4511 diff --git a/changelog/unreleased/pull-4511 b/changelog/unreleased/pull-4511 new file mode 100644 index 000000000..60c5659b6 --- /dev/null +++ b/changelog/unreleased/pull-4511 @@ -0,0 +1,7 @@ +Enhancement: Include inode numbers in JSON output for find and ls + +Restic used to omit the inode numbers in the JSON messages emitted for nodes by +the `ls` command as well as for matches by the `find` command. It now includes +those values whenever they are available. + +https://github.com/restic/restic/pull/4511 diff --git a/cmd/restic/cmd_find.go b/cmd/restic/cmd_find.go index 9c21cc9bb..abcf4f829 100644 --- a/cmd/restic/cmd_find.go +++ b/cmd/restic/cmd_find.go @@ -126,7 +126,6 @@ func (s *statefulOutput) PrintPatternJSON(path string, node *restic.Node) { // Make the following attributes disappear Name byte `json:"name,omitempty"` - Inode byte `json:"inode,omitempty"` ExtendedAttributes byte `json:"extended_attributes,omitempty"` Device byte `json:"device,omitempty"` Content byte `json:"content,omitempty"` diff --git a/cmd/restic/cmd_ls.go b/cmd/restic/cmd_ls.go index a0c07a752..fa2f9fbc2 100644 --- a/cmd/restic/cmd_ls.go +++ b/cmd/restic/cmd_ls.go @@ -87,6 +87,7 @@ func lsNodeJSON(enc *json.Encoder, path string, node *restic.Node) error { ModTime time.Time `json:"mtime,omitempty"` AccessTime time.Time `json:"atime,omitempty"` ChangeTime time.Time `json:"ctime,omitempty"` + Inode uint64 `json:"inode,omitempty"` StructType string `json:"struct_type"` // "node" size uint64 // Target for Size pointer. @@ -102,6 +103,7 @@ func lsNodeJSON(enc *json.Encoder, path string, node *restic.Node) error { ModTime: node.ModTime, AccessTime: node.AccessTime, ChangeTime: node.ChangeTime, + Inode: node.Inode, StructType: "node", } // Always print size for regular files, even when empty, diff --git a/doc/075_scripting.rst b/doc/075_scripting.rst index 9b9d676a9..71ecd4c2b 100644 --- a/doc/075_scripting.rst +++ b/doc/075_scripting.rst @@ -277,6 +277,8 @@ Match object +-----------------+----------------------------------------------+ | ``group`` | Name of group | +-----------------+----------------------------------------------+ +| ``inode`` | Inode number | ++-----------------+----------------------------------------------+ | ``mode`` | UNIX file mode, shorthand of ``permissions`` | +-----------------+----------------------------------------------+ | ``device_id`` | OS specific device identifier | @@ -470,6 +472,8 @@ node +-----------------+--------------------------+ | ``ctime`` | Node creation time | +-----------------+--------------------------+ +| ``inode`` | Inode number of node | ++-----------------+--------------------------+ restore