From 22475729ce46c949d5c2825b40d774e52e3055fa Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Sun, 19 Aug 2018 09:03:47 -0600 Subject: [PATCH] Select specific Node fields for listing --- cmd/restic/cmd_ls.go | 26 +++++++++++++++++++++++--- internal/restic/node.go | 2 +- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/cmd/restic/cmd_ls.go b/cmd/restic/cmd_ls.go index 3bfd53f9e..c91cb5af7 100644 --- a/cmd/restic/cmd_ls.go +++ b/cmd/restic/cmd_ls.go @@ -3,7 +3,9 @@ package main import ( "context" "encoding/json" + "os" "strings" + "time" "github.com/spf13/cobra" @@ -68,8 +70,17 @@ type lsSnapshot struct { } type lsNode struct { - *restic.Node - StructType string `json:"struct_type"` // "node" + Name string `json:"name"` + Type string `json:"type"` + Path string `json:"path"` + UID uint32 `json:"uid"` + GID uint32 `json:"gid"` + Size uint64 `json:"size,omitempty"` + Mode os.FileMode `json:"mode,omitempty"` + ModTime time.Time `json:"mtime,omitempty"` + AccessTime time.Time `json:"atime,omitempty"` + ChangeTime time.Time `json:"ctime,omitempty"` + StructType string `json:"struct_type"` // "node" } func runLs(opts LsOptions, gopts GlobalOptions, args []string) error { @@ -153,7 +164,16 @@ func runLs(opts LsOptions, gopts GlobalOptions, args []string) error { printNode = func(path string, node *restic.Node) { enc.Encode(lsNode{ - Node: node, + Name: node.Name, + Type: node.Type, + Path: path, + UID: node.UID, + GID: node.GID, + Size: node.Size, + Mode: node.Mode, + ModTime: node.ModTime, + AccessTime: node.AccessTime, + ChangeTime: node.ChangeTime, StructType: "node", }) } diff --git a/internal/restic/node.go b/internal/restic/node.go index 24fe4598e..cec7938e5 100644 --- a/internal/restic/node.go +++ b/internal/restic/node.go @@ -50,7 +50,7 @@ type Node struct { Error string `json:"error,omitempty"` - Path string `json:"path"` + Path string `json:"-"` } // Nodes is a slice of nodes that can be sorted.