mirror of
https://github.com/gilbertchen/duplicacy
synced 2025-12-18 09:13:17 +00:00
Align snapshot times to the beginning of days when calculating the differences
This commit is contained in:
@@ -170,6 +170,16 @@ func (collection *FossilCollection) IsEmpty() bool {
|
|||||||
return len(collection.Fossils) == 0 && len(collection.Temporaries) == 0
|
return len(collection.Fossils) == 0 && len(collection.Temporaries) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculates the number of days between two times ignoring the hours, minutes and seconds.
|
||||||
|
func getDaysBetween(start int64, end int64) int {
|
||||||
|
startTime := time.Unix(start, 0).In(time.Now().Location())
|
||||||
|
endTime := time.Unix(end, 0).In(time.Now().Location())
|
||||||
|
startDate := time.Date(startTime.Year(), startTime.Month(), startTime.Day(), 0, 0, 0, 0, startTime.Location())
|
||||||
|
endDate := time.Date(endTime.Year(), endTime.Month(), endTime.Day(), 0, 0, 0, 0, endTime.Location())
|
||||||
|
hours := int(endDate.Sub(startDate).Hours())
|
||||||
|
return (hours + 1) / 24
|
||||||
|
}
|
||||||
|
|
||||||
// SnapshotManager is mainly responsible for downloading, and deleting snapshots.
|
// SnapshotManager is mainly responsible for downloading, and deleting snapshots.
|
||||||
type SnapshotManager struct {
|
type SnapshotManager struct {
|
||||||
|
|
||||||
@@ -1907,7 +1917,7 @@ func (manager *SnapshotManager) PruneSnapshots(selfID string, snapshotID string,
|
|||||||
|
|
||||||
// Find out which retent policy applies based on the age.
|
// Find out which retent policy applies based on the age.
|
||||||
for i < len(retentionPolicies) &&
|
for i < len(retentionPolicies) &&
|
||||||
int(now-snapshot.StartTime) < retentionPolicies[i].Age*secondsInDay {
|
getDaysBetween(snapshot.StartTime, now) < retentionPolicies[i].Age {
|
||||||
i++
|
i++
|
||||||
lastSnapshotTime = 0
|
lastSnapshotTime = 0
|
||||||
}
|
}
|
||||||
@@ -1920,9 +1930,8 @@ func (manager *SnapshotManager) PruneSnapshots(selfID string, snapshotID string,
|
|||||||
snapshot.Flag = true
|
snapshot.Flag = true
|
||||||
toBeDeleted++
|
toBeDeleted++
|
||||||
} else if lastSnapshotTime != 0 &&
|
} else if lastSnapshotTime != 0 &&
|
||||||
int(snapshot.StartTime-lastSnapshotTime) < retentionPolicies[i].Interval*secondsInDay-600 {
|
getDaysBetween(lastSnapshotTime, snapshot.StartTime) < retentionPolicies[i].Interval {
|
||||||
// Delete the snapshot if it is too close to the last kept one. Note that a tolerance of 10
|
// Delete the snapshot if it is too close to the last kept one.
|
||||||
// minutes was subtracted from the interval.
|
|
||||||
LOG_DEBUG("SNAPSHOT_DELETE", "Snapshot %s at revision %d to be deleted - older than %d days, less than %d days from previous",
|
LOG_DEBUG("SNAPSHOT_DELETE", "Snapshot %s at revision %d to be deleted - older than %d days, less than %d days from previous",
|
||||||
snapshot.ID, snapshot.Revision, retentionPolicies[i].Age, retentionPolicies[i].Interval)
|
snapshot.ID, snapshot.Revision, retentionPolicies[i].Age, retentionPolicies[i].Interval)
|
||||||
snapshot.Flag = true
|
snapshot.Flag = true
|
||||||
|
|||||||
Reference in New Issue
Block a user