forget: Treat -1 as forever for all "last n" opts

This commit is contained in:
Torben Giesselmann 2023-03-04 19:01:37 -08:00
parent 6aca7dac21
commit b77b0749fa
5 changed files with 3664 additions and 3 deletions

View file

@ -108,8 +108,6 @@ func verifyForgetOptions(opts *ForgetOptions) error {
}
if !negValFound {
// durations := [6]restic.Duration{opts.Within, opts.WithinHourly, opts.WithinDaily,
// opts.WithinMonthly, opts.WithinWeekly, opts.WithinYearly}
for _, d := range [6]restic.Duration{opts.Within, opts.WithinHourly, opts.WithinDaily,
opts.WithinMonthly, opts.WithinWeekly, opts.WithinYearly} {
if d.Hours < -1 || d.Days < -1 || d.Months < -1 || d.Years < -1 {

View file

@ -260,13 +260,16 @@ func ApplyPolicy(list Snapshots, p ExpirePolicy) (keep, remove Snapshots, reason
// Now update the other buckets and see if they have some counts left.
for i, b := range buckets {
if b.Count > 0 {
if b.Count <= -1 || b.Count > 0 {
val := b.bucker(cur.Time, nr)
if val != b.Last {
debug.Log("keep %v %v, bucker %v, val %v\n", cur.Time, cur.id.Str(), i, val)
keepSnap = true
buckets[i].Last = val
buckets[i].Count--
if buckets[i].Count < -1 {
buckets[i].Count = -1
}
keepSnapReasons = append(keepSnapReasons, b.reason)
}
}

View file

@ -239,6 +239,12 @@ func TestApplyPolicy(t *testing.T) {
WithinWeekly: parseDuration("1m"),
WithinMonthly: parseDuration("1y"),
WithinYearly: parseDuration("9999y")},
{Last: -1}, // keep all
{Last: -1, Hourly: -1}, // keep all (Last overrides Hourly)
// {Hourly: -1}, // keep all hourlies
// {Daily: -1}, // keep all dailies
// {Daily: -1, Weekly: 4}, // keep all dailies and 4 weeklies
// {Daily: 3, Weekly: -1}, // keep 3 dailies and all weeklies
}
for i, p := range tests {

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff