mirror of
https://github.com/octoleo/restic.git
synced 2024-12-23 03:18:55 +00:00
Merge pull request #3573 from magandrez/feat/ls-report-symbolic-notation
Provide mode in symbolic notation for `restic ls --json`
This commit is contained in:
commit
f7a9b90eb9
8
changelog/unreleased/issue-3542
Normal file
8
changelog/unreleased/issue-3542
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
Enhancement: Add file mode in symbolic notation to `ls --json`
|
||||||
|
|
||||||
|
Now `restic ls --json` provides mode in symbolic notation aligned
|
||||||
|
with `restic find --json`.
|
||||||
|
|
||||||
|
https://github.com/restic/restic/issues/3542
|
||||||
|
https://github.com/restic/restic/pull/3573
|
||||||
|
https://forum.restic.net/t/restic-ls-understanding-file-mode-with-json/4371
|
@ -84,6 +84,7 @@ func lsNodeJSON(enc *json.Encoder, path string, node *restic.Node) error {
|
|||||||
GID uint32 `json:"gid"`
|
GID uint32 `json:"gid"`
|
||||||
Size *uint64 `json:"size,omitempty"`
|
Size *uint64 `json:"size,omitempty"`
|
||||||
Mode os.FileMode `json:"mode,omitempty"`
|
Mode os.FileMode `json:"mode,omitempty"`
|
||||||
|
Permissions string `json:"permissions,omitempty"`
|
||||||
ModTime time.Time `json:"mtime,omitempty"`
|
ModTime time.Time `json:"mtime,omitempty"`
|
||||||
AccessTime time.Time `json:"atime,omitempty"`
|
AccessTime time.Time `json:"atime,omitempty"`
|
||||||
ChangeTime time.Time `json:"ctime,omitempty"`
|
ChangeTime time.Time `json:"ctime,omitempty"`
|
||||||
@ -98,6 +99,7 @@ func lsNodeJSON(enc *json.Encoder, path string, node *restic.Node) error {
|
|||||||
GID: node.GID,
|
GID: node.GID,
|
||||||
size: node.Size,
|
size: node.Size,
|
||||||
Mode: node.Mode,
|
Mode: node.Mode,
|
||||||
|
Permissions: node.Mode.String(),
|
||||||
ModTime: node.ModTime,
|
ModTime: node.ModTime,
|
||||||
AccessTime: node.AccessTime,
|
AccessTime: node.AccessTime,
|
||||||
ChangeTime: node.ChangeTime,
|
ChangeTime: node.ChangeTime,
|
||||||
|
@ -18,6 +18,7 @@ func TestLsNodeJSON(t *testing.T) {
|
|||||||
expect string
|
expect string
|
||||||
}{
|
}{
|
||||||
// Mode is omitted when zero.
|
// Mode is omitted when zero.
|
||||||
|
// Permissions, by convention is "-" per mode bit
|
||||||
{
|
{
|
||||||
path: "/bar/baz",
|
path: "/bar/baz",
|
||||||
Node: restic.Node{
|
Node: restic.Node{
|
||||||
@ -31,7 +32,7 @@ func TestLsNodeJSON(t *testing.T) {
|
|||||||
Group: "nobodies",
|
Group: "nobodies",
|
||||||
Links: 1,
|
Links: 1,
|
||||||
},
|
},
|
||||||
expect: `{"name":"baz","type":"file","path":"/bar/baz","uid":10000000,"gid":20000000,"size":12345,"mtime":"0001-01-01T00:00:00Z","atime":"0001-01-01T00:00:00Z","ctime":"0001-01-01T00:00:00Z","struct_type":"node"}`,
|
expect: `{"name":"baz","type":"file","path":"/bar/baz","uid":10000000,"gid":20000000,"size":12345,"permissions":"----------","mtime":"0001-01-01T00:00:00Z","atime":"0001-01-01T00:00:00Z","ctime":"0001-01-01T00:00:00Z","struct_type":"node"}`,
|
||||||
},
|
},
|
||||||
|
|
||||||
// Even empty files get an explicit size.
|
// Even empty files get an explicit size.
|
||||||
@ -48,7 +49,7 @@ func TestLsNodeJSON(t *testing.T) {
|
|||||||
Group: "not printed",
|
Group: "not printed",
|
||||||
Links: 0xF00,
|
Links: 0xF00,
|
||||||
},
|
},
|
||||||
expect: `{"name":"empty","type":"file","path":"/foo/empty","uid":1001,"gid":1001,"size":0,"mtime":"0001-01-01T00:00:00Z","atime":"0001-01-01T00:00:00Z","ctime":"0001-01-01T00:00:00Z","struct_type":"node"}`,
|
expect: `{"name":"empty","type":"file","path":"/foo/empty","uid":1001,"gid":1001,"size":0,"permissions":"----------","mtime":"0001-01-01T00:00:00Z","atime":"0001-01-01T00:00:00Z","ctime":"0001-01-01T00:00:00Z","struct_type":"node"}`,
|
||||||
},
|
},
|
||||||
|
|
||||||
// Non-regular files do not get a size.
|
// Non-regular files do not get a size.
|
||||||
@ -61,7 +62,7 @@ func TestLsNodeJSON(t *testing.T) {
|
|||||||
Mode: os.ModeSymlink | 0777,
|
Mode: os.ModeSymlink | 0777,
|
||||||
LinkTarget: "not printed",
|
LinkTarget: "not printed",
|
||||||
},
|
},
|
||||||
expect: `{"name":"link","type":"symlink","path":"/foo/link","uid":0,"gid":0,"mode":134218239,"mtime":"0001-01-01T00:00:00Z","atime":"0001-01-01T00:00:00Z","ctime":"0001-01-01T00:00:00Z","struct_type":"node"}`,
|
expect: `{"name":"link","type":"symlink","path":"/foo/link","uid":0,"gid":0,"mode":134218239,"permissions":"Lrwxrwxrwx","mtime":"0001-01-01T00:00:00Z","atime":"0001-01-01T00:00:00Z","ctime":"0001-01-01T00:00:00Z","struct_type":"node"}`,
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -74,7 +75,7 @@ func TestLsNodeJSON(t *testing.T) {
|
|||||||
AccessTime: time.Date(2021, 2, 3, 4, 5, 6, 7, time.UTC),
|
AccessTime: time.Date(2021, 2, 3, 4, 5, 6, 7, time.UTC),
|
||||||
ChangeTime: time.Date(2022, 3, 4, 5, 6, 7, 8, time.UTC),
|
ChangeTime: time.Date(2022, 3, 4, 5, 6, 7, 8, time.UTC),
|
||||||
},
|
},
|
||||||
expect: `{"name":"directory","type":"dir","path":"/some/directory","uid":0,"gid":0,"mode":2147484141,"mtime":"2020-01-02T03:04:05Z","atime":"2021-02-03T04:05:06.000000007Z","ctime":"2022-03-04T05:06:07.000000008Z","struct_type":"node"}`,
|
expect: `{"name":"directory","type":"dir","path":"/some/directory","uid":0,"gid":0,"mode":2147484141,"permissions":"drwxr-xr-x","mtime":"2020-01-02T03:04:05Z","atime":"2021-02-03T04:05:06.000000007Z","ctime":"2022-03-04T05:06:07.000000008Z","struct_type":"node"}`,
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
Loading…
Reference in New Issue
Block a user