RestoreEngine

class RestoreEngine(engine: SyncEngine, storage: CloudStorage, recordStore: RestoreRecordStore, placement: RestorePlacement = RestorePlacement.KeepDownloaded, clock: () -> Long = { Clock.System.now().toEpochMilliseconds() }, maxAttempts: Int = 3, newRunId: () -> String = { Random.nextLong().toULong().toString(radix = 16) })(source)

Resumable download of a pinned remote set. Required files first (the commit boundary), then optional files best-effort with maxAttempts tries each. Progress is durable per file; resume revalidates the source through SyncEngine.probe before continuing, so a backup that changed under the plan is reported as RestoreError.SourceChanged instead of being mixed in.

Files are downloaded to their toLocalPath and then offered to placement group by group. Stopping is cancelling the calling coroutine: the record is saved after every file and every placement, so a later resume continues from exactly there.

Set SyncEngine.setHold to WriteHold.RestoreRunning before starting and release it when your app has imported the files; the engine does not touch the hold itself.

Constructors

Link copied to clipboard
constructor(engine: SyncEngine, storage: CloudStorage, recordStore: RestoreRecordStore, placement: RestorePlacement = RestorePlacement.KeepDownloaded, clock: () -> Long = { Clock.System.now().toEpochMilliseconds() }, maxAttempts: Int = 3, newRunId: () -> String = { Random.nextLong().toULong().toString(radix = 16) })

Functions

Link copied to clipboard
fun clear()
Link copied to clipboard
Link copied to clipboard
suspend fun resume(resetAttempts: Boolean = false, onProgress: (RestoreProgress) -> Unit = {}): RestoreOutcome

Continues the recorded chain after revalidating its source. Done files are never downloaded again. resetAttempts is the explicit retry: files that reached the attempt cap get a fresh set of tries; a plain resume keeps the cap.

Link copied to clipboard
suspend fun start(plan: RestorePlan, onProgress: (RestoreProgress) -> Unit = {}): RestoreOutcome

Starts a new chain for plan, replacing any previous record.