core/model_management/utils/download_temp_reclaim library

Decision logic + filesystem walk for reclaiming orphaned background_downloader partial temp files (#383), split out so both the pure predicate and the directory sweep are testable — the predicate as a pure unit test, the sweep as an on-device integration test — without the surrounding FileDownloader / path_provider / gate machinery.

MobileModelManager._reclaimOrphanedDownloadTemps owns the SAFETY GATES (Android-only, no active downloads, resumeFromBackground() first, the resume keep-set) and calls sweepOrphanedDownloadTemps to do the walk.

Enums

ReclaimDecision
Outcome of reconciling one persisted resume record against the current task-ID scheme during reclaim (#383/R2).

Constants

kDownloadTempMinReclaimAge → const Duration
How recently a temp file must have been touched to be considered possibly LIVE (a download can start writing a beat before its task is Dart-visible). Only temps older than this are candidates for deletion.
kDownloadTempPrefix → const String
Filename prefix background_downloader gives every partial temp file (com.bbflight.background_downloader<Random.nextInt()>, no extension).

Functions

isDownloadFragmentName(String basename) bool
Whether basename is a background_downloader partial temp file (#383/#3).
reconcileResumeRecord({required String taskId, required String expectedId, required bool isNativeRunning, required Duration tempAge, Duration minAge = kDownloadTempMinReclaimAge}) ReclaimDecision
Decide what to do with a group-scoped resume record whose temp is tempAge old.
shouldReclaimDownloadTemp({required String basename, required String path, required Set<String> keepPaths, required Duration age, Duration minAge = kDownloadTempMinReclaimAge}) bool
Whether the file at path (basename basename) is an orphaned download temp safe to delete.
sweepOrphanedDownloadTemps(Directory dir, {required Set<String> keepPaths, Duration minAge = kDownloadTempMinReclaimAge, DateTime? now}) Future<int>
Walks dir (non-recursive) and deletes every file for which shouldReclaimDownloadTemp is true. Returns the number deleted.