From b69c6408a6cec3700915469c285c279a4356e9dc Mon Sep 17 00:00:00 2001 From: Srigovind Nayak Date: Sat, 7 Sep 2024 15:00:21 +0530 Subject: [PATCH] forget: make oldest snapshot marker more strict Now, a snapshot is only marked as oldest if it's the last in the list AND its values matches the last seen value for that bucket. Also, updated the corresponding golden files for the tests. --- internal/restic/snapshot_policy.go | 10 +++++----- internal/restic/testdata/policy_keep_snapshots_36 | 2 +- internal/restic/testdata/policy_keep_snapshots_37 | 4 ++-- internal/restic/testdata/policy_keep_snapshots_38 | 2 +- internal/restic/testdata/policy_keep_snapshots_4 | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/restic/snapshot_policy.go b/internal/restic/snapshot_policy.go index f5c90d6e4..28f871f4a 100644 --- a/internal/restic/snapshot_policy.go +++ b/internal/restic/snapshot_policy.go @@ -256,13 +256,13 @@ func ApplyPolicy(list Snapshots, p ExpirePolicy) (keep, remove Snapshots, reason if val != b.Last || nr == len(list)-1 { debug.Log("keep %v %v, bucker %v, val %v\n", cur.Time, cur.id.Str(), i, val) keepSnap = true + if val == b.Last && nr == len(list)-1 { + b.reason = fmt.Sprintf("oldest %v", b.reason) + } buckets[i].Last = val if buckets[i].Count > 0 { buckets[i].Count-- } - if nr == len(list)-1 { - b.reason = fmt.Sprintf("oldest %v", b.reason) - } keepSnapReasons = append(keepSnapReasons, b.reason) } } @@ -278,10 +278,10 @@ func ApplyPolicy(list Snapshots, p ExpirePolicy) (keep, remove Snapshots, reason if val != b.Last || nr == len(list)-1 { debug.Log("keep %v, time %v, ID %v, bucker %v, val %v %v\n", b.reason, cur.Time, cur.id.Str(), i, val, b.Last) keepSnap = true - bucketsWithin[i].Last = val - if nr == len(list)-1 { + if val == b.Last && nr == len(list)-1 { b.reason = fmt.Sprintf("oldest %v", b.reason) } + bucketsWithin[i].Last = val keepSnapReasons = append(keepSnapReasons, fmt.Sprintf("%v %v", b.reason, b.Within)) } } diff --git a/internal/restic/testdata/policy_keep_snapshots_36 b/internal/restic/testdata/policy_keep_snapshots_36 index 6023e993e..cce4cf537 100644 --- a/internal/restic/testdata/policy_keep_snapshots_36 +++ b/internal/restic/testdata/policy_keep_snapshots_36 @@ -1978,7 +1978,7 @@ "paths": null }, "matches": [ - "oldest last snapshot" + "last snapshot" ], "counters": { "last": -1 diff --git a/internal/restic/testdata/policy_keep_snapshots_37 b/internal/restic/testdata/policy_keep_snapshots_37 index 0cf643ab6..9856a83d6 100644 --- a/internal/restic/testdata/policy_keep_snapshots_37 +++ b/internal/restic/testdata/policy_keep_snapshots_37 @@ -2169,8 +2169,8 @@ "paths": null }, "matches": [ - "oldest last snapshot", - "oldest hourly snapshot" + "last snapshot", + "hourly snapshot" ], "counters": { "last": -1, diff --git a/internal/restic/testdata/policy_keep_snapshots_38 b/internal/restic/testdata/policy_keep_snapshots_38 index ef4eb6777..f5d7136d4 100644 --- a/internal/restic/testdata/policy_keep_snapshots_38 +++ b/internal/restic/testdata/policy_keep_snapshots_38 @@ -1708,7 +1708,7 @@ "paths": null }, "matches": [ - "oldest hourly snapshot" + "hourly snapshot" ], "counters": { "hourly": -1 diff --git a/internal/restic/testdata/policy_keep_snapshots_4 b/internal/restic/testdata/policy_keep_snapshots_4 index 66e5cebe2..ff572d6a0 100644 --- a/internal/restic/testdata/policy_keep_snapshots_4 +++ b/internal/restic/testdata/policy_keep_snapshots_4 @@ -1978,7 +1978,7 @@ "paths": null }, "matches": [ - "oldest last snapshot" + "last snapshot" ], "counters": { "last": 97