diff --git a/src/cmds/restic/cmd_forget.go b/src/cmds/restic/cmd_forget.go index 350b02597..52db6fea0 100644 --- a/src/cmds/restic/cmd_forget.go +++ b/src/cmds/restic/cmd_forget.go @@ -49,20 +49,38 @@ func (cmd CmdForget) Usage() string { func printSnapshots(w io.Writer, snapshots restic.Snapshots) { tab := NewTable() - tab.Header = fmt.Sprintf("%-8s %-19s %-10s %s", "ID", "Date", "Host", "Directory") - tab.RowFormat = "%-8s %-19s %-10s %s" + tab.Header = fmt.Sprintf("%-8s %-19s %-10s %-10s %s", "ID", "Date", "Host", "Tags", "Directory") + tab.RowFormat = "%-8s %-19s %-10s %-10s %s" for _, sn := range snapshots { if len(sn.Paths) == 0 { continue } - id := sn.ID() - tab.Rows = append(tab.Rows, []interface{}{id.Str(), sn.Time.Format(TimeFormat), sn.Hostname, sn.Paths[0]}) - if len(sn.Paths) > 1 { - for _, path := range sn.Paths[1:] { - tab.Rows = append(tab.Rows, []interface{}{"", "", "", path}) + firstTag := "" + if len(sn.Tags) > 0 { + firstTag = sn.Tags[0] + } + + tab.Rows = append(tab.Rows, []interface{}{sn.ID().Str(), sn.Time.Format(TimeFormat), sn.Hostname, firstTag, sn.Paths[0]}) + + rows := len(sn.Paths) + if len(sn.Tags) > rows { + rows = len(sn.Tags) + } + + for i := 1; i < rows; i++ { + path := "" + if len(sn.Paths) > i { + path = sn.Paths[i] } + + tag := "" + if len(sn.Tags) > i { + tag = sn.Tags[i] + } + + tab.Rows = append(tab.Rows, []interface{}{"", "", "", tag, path}) } } diff --git a/src/restic/snapshot_filter.go b/src/restic/snapshot_filter.go index 7d5b2e59a..d616468ea 100644 --- a/src/restic/snapshot_filter.go +++ b/src/restic/snapshot_filter.go @@ -177,11 +177,15 @@ func (f *filter) keepTags(tags []string) { return } + unprocessed := f.Unprocessed[:0] for _, sn := range f.Unprocessed { if sn.HasTags(tags) { f.Keep = append(f.Keep, sn) + continue } + unprocessed = append(unprocessed, sn) } + f.Unprocessed = unprocessed } // keepLast marks the last n snapshots as to be kept. diff --git a/src/restic/snapshot_filter_test.go b/src/restic/snapshot_filter_test.go index beca742a2..64e8ccc13 100644 --- a/src/restic/snapshot_filter_test.go +++ b/src/restic/snapshot_filter_test.go @@ -233,10 +233,10 @@ func TestApplyPolicy(t *testing.T) { } for _, sn := range keep { - t.Logf("test %d: keep snapshot at %v\n", i, sn.Time) + t.Logf("test %d: keep snapshot at %v %s\n", i, sn.Time, sn.Tags) } for _, sn := range remove { - t.Logf("test %d: forget snapshot at %v\n", i, sn.Time) + t.Logf("test %d: forget snapshot at %v %s\n", i, sn.Time, sn.Tags) } goldenFilename := filepath.Join("testdata", fmt.Sprintf("expired_snapshots_%d", i)) diff --git a/src/restic/testdata/expired_snapshots_18 b/src/restic/testdata/expired_snapshots_18 index 5898b0950..cd857c51a 100644 --- a/src/restic/testdata/expired_snapshots_18 +++ b/src/restic/testdata/expired_snapshots_18 @@ -7,14 +7,6 @@ "foo" ] }, - { - "time": "2014-11-12T10:20:30Z", - "tree": null, - "paths": null, - "tags": [ - "foo" - ] - }, { "time": "2014-11-10T10:20:30Z", "tree": null, @@ -23,14 +15,6 @@ "foo" ] }, - { - "time": "2014-11-08T10:20:30Z", - "tree": null, - "paths": null, - "tags": [ - "foo" - ] - }, { "time": "2014-10-22T10:20:30Z", "tree": null, @@ -39,14 +23,6 @@ "foo" ] }, - { - "time": "2014-10-20T10:20:30Z", - "tree": null, - "paths": null, - "tags": [ - "foo" - ] - }, { "time": "2014-10-11T10:20:30Z", "tree": null, @@ -55,14 +31,6 @@ "foo" ] }, - { - "time": "2014-10-10T10:20:30Z", - "tree": null, - "paths": null, - "tags": [ - "foo" - ] - }, { "time": "2014-10-09T10:20:30Z", "tree": null, @@ -71,14 +39,6 @@ "foo" ] }, - { - "time": "2014-10-08T10:20:30Z", - "tree": null, - "paths": null, - "tags": [ - "foo" - ] - }, { "time": "2014-10-06T10:20:30Z", "tree": null, @@ -87,14 +47,6 @@ "foo" ] }, - { - "time": "2014-10-05T10:20:30Z", - "tree": null, - "paths": null, - "tags": [ - "foo" - ] - }, { "time": "2014-10-02T10:20:30Z", "tree": null, @@ -102,13 +54,5 @@ "tags": [ "foo" ] - }, - { - "time": "2014-10-01T10:20:30Z", - "tree": null, - "paths": null, - "tags": [ - "foo" - ] } ] \ No newline at end of file