forked from TrueCloudLab/restic
forget: Ensure future snapshots do not affect --keep-within-*
Ensure that only snapshots made in the past are taken into account when running restic forget with the within switches (--keep-within, --keep-within- hourly, and friends)
This commit is contained in:
parent
74ebc650ab
commit
2081bd12fb
1 changed files with 6 additions and 2 deletions
|
@ -147,15 +147,19 @@ func always(d time.Time, nr int) int {
|
||||||
return nr
|
return nr
|
||||||
}
|
}
|
||||||
|
|
||||||
// findLatestTimestamp returns the time stamp for the newest snapshot.
|
// findLatestTimestamp returns the time stamp for the latest (newest) snapshot,
|
||||||
|
// for use with policies based on time relative to latest.
|
||||||
func findLatestTimestamp(list Snapshots) time.Time {
|
func findLatestTimestamp(list Snapshots) time.Time {
|
||||||
if len(list) == 0 {
|
if len(list) == 0 {
|
||||||
panic("list of snapshots is empty")
|
panic("list of snapshots is empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
var latest time.Time
|
var latest time.Time
|
||||||
|
now := time.Now()
|
||||||
for _, sn := range list {
|
for _, sn := range list {
|
||||||
if sn.Time.After(latest) {
|
// Find the latest snapshot in the list
|
||||||
|
// The latest snapshot must, however, not be in the future.
|
||||||
|
if sn.Time.After(latest) && sn.Time.Before(now) {
|
||||||
latest = sn.Time
|
latest = sn.Time
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue