MCPcopy
hub / github.com/wal-g/wal-g / FindTargetRetainAfterTime

Method FindTargetRetainAfterTime

internal/delete_handler.go:316–352  ·  view source on GitHub ↗

TODO: unit tests

(retentionCount int, timeLine time.Time, modifier int,
)

Source from the content-addressed store, hash-verified

314
315// TODO: unit tests
316func (h *DeleteHandler) FindTargetRetainAfterTime(retentionCount int, timeLine time.Time, modifier int,
317) (BackupObject, error) {
318 choiceFuncRetain := getRetainChoiceFunc(retentionCount, modifier)
319 if choiceFuncRetain == nil {
320 return nil, utility.NewForbiddenActionError("Not allowed modifier for 'delete retain'")
321 }
322 choiceFuncAfter := func(object BackupObject) bool {
323 backupTime := object.GetBackupTime()
324 timeCheck := timeLine.Before(backupTime) || timeLine.Equal(backupTime)
325 if modifier == NoDeleteModifier {
326 return timeCheck
327 }
328 return timeCheck && object.IsFullBackup()
329 }
330
331 target1, err := findTarget(h.backups, h.greater, choiceFuncRetain)
332 if err != nil && err != errNotFound {
333 return nil, err
334 }
335 target2, err := findTarget(h.backups, h.less, choiceFuncAfter)
336 if err != nil && err != errNotFound {
337 return nil, err
338 }
339
340 if target1 == nil {
341 return target2, nil
342 }
343 if target2 == nil {
344 return target1, nil
345 }
346
347 if h.greater(target2, target1) {
348 return target1, nil
349 }
350
351 return target2, nil
352}
353
354func (h *DeleteHandler) DeleteEverything(confirmed bool) {
355 filter := func(object storage.Object) bool { return true }

Callers 2

FindTargetRetainAfterMethod · 0.95

Calls 5

NewForbiddenActionErrorFunction · 0.92
getRetainChoiceFuncFunction · 0.85
findTargetFunction · 0.85
GetBackupTimeMethod · 0.65
IsFullBackupMethod · 0.65

Tested by 1