The download-manager uses a three-stage pipeline to determine the state of a file download. This ensures data integrity, correct UI representation, and proper operational cleanup.
1. Validation (reduce_to_checked_file_state)
Determines if a file on disk is Valid, Invalid, or Missing using CRC (Cyclic Redundancy Check).
- Optimization: Valid files receive a
.crc cache file. This makes subsequent launches ~100x faster for large files by avoiding recalculation. The cache is invalidated if the file changes.
2. Display State (reduce_to_file_download_state)
Maps validation results to user-facing states for the UI:
- Downloaded: Any file that is
Valid is immediately shown as Downloaded. - Downloading/Paused/NotDownloaded: Derived from a combination of the
checked_state, resume_state, task_state, and expected_bytes.
3. Reconciliation (reconcile_to_internal_state)
Performs side effects like file deletion or task cancellation to determine the InternalDownloadState for operations.
- Valid Files: Always result in
Downloaded state; unnecessary artifacts (like resume files) are cleaned up. - Invalid/Missing Files: May trigger file deletion, resume data production, or task cancellation based on whether the file is partial or corrupted.