Allow --tag and --keep-tag to match untagged snapshots

This commit is contained in:
David le Blanc
2021-07-15 11:38:15 +10:00
committed by Leo R. Lundgren
parent 5571c3f7fd
commit 326fefcd80
5 changed files with 43 additions and 6 deletions

View File

@@ -195,6 +195,9 @@ func (sn *Snapshot) hasTag(tag string) bool {
// HasTags returns true if the snapshot has all the tags in l.
func (sn *Snapshot) HasTags(l []string) bool {
for _, tag := range l {
if tag == "" && len(sn.Tags) == 0 {
return true
}
if !sn.hasTag(tag) {
return false
}

View File

@@ -14,3 +14,13 @@ func TestNewSnapshot(t *testing.T) {
_, err := restic.NewSnapshot(paths, nil, "foo", time.Now())
rtest.OK(t, err)
}
func TestTagList(t *testing.T) {
paths := []string{"/home/foobar"}
tags := []string{""}
sn, _ := restic.NewSnapshot(paths, nil, "foo", time.Now())
r := sn.HasTags(tags)
rtest.Assert(t, r, "Failed to match untagged snapshot")
}