MCPcopy Index your code
hub / github.com/kopia/kopia / GetTwoLatestSnapshotsForASource

Function GetTwoLatestSnapshotsForASource

internal/diff/diff.go:444–462  ·  view source on GitHub ↗

GetTwoLatestSnapshotsForASource fetches two latest snapshot manifests for a given source if they exist.

(ctx context.Context, rep repo.Repository, source snapshot.SourceInfo)

Source from the content-addressed store, hash-verified

442
443// GetTwoLatestSnapshotsForASource fetches two latest snapshot manifests for a given source if they exist.
444func GetTwoLatestSnapshotsForASource(ctx context.Context, rep repo.Repository, source snapshot.SourceInfo) (secondLast, last *snapshot.Manifest, err error) {
445 snapshots, err := snapshot.ListSnapshots(ctx, rep, source)
446 if err != nil {
447 return nil, nil, errors.Wrap(err, "failed to list all snapshots")
448 }
449
450 const minimumReqSnapshots = 2
451
452 sizeSnapshots := len(snapshots)
453 if sizeSnapshots < minimumReqSnapshots {
454 return nil, nil, errors.New("snapshot source has less than two snapshots")
455 }
456
457 sort.Slice(snapshots, func(i, j int) bool {
458 return snapshots[i].StartTime.Before(snapshots[j].StartTime)
459 })
460
461 return snapshots[sizeSnapshots-2], snapshots[sizeSnapshots-1], nil
462}

Callers 1

Calls 2

ListSnapshotsFunction · 0.92
BeforeMethod · 0.45

Tested by 1