mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-08-15 06:56:30 +00:00
fix: Base the disk space check on remaining bytes when resuming
The check ran before resume state was read and always demanded 1.5x the full APK size. Bytes already sitting in download_temp.apk have already consumed storage, so on a low-storage device an interrupted download could fail every resume with "Insufficient storage" even when only a small tail was left to fetch. Read the resume state first and check space for the remaining bytes only. A fresh download still checks the full size, and a complete temp file needs no extra space since promotion is a rename. Addresses the Codex review finding on UniversalApkManager. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
74225c21c3
commit
8a54cbb4c7
@ -219,9 +219,6 @@ class UniversalApkManager(private val context: Context) {
|
||||
Log.d(TAG, "Downloading from: $url")
|
||||
Log.d(TAG, "Expected size: ${expectedSize / 1024 / 1024}MB")
|
||||
|
||||
// Check available disk space before downloading
|
||||
checkDiskSpace(expectedSize)
|
||||
|
||||
val tempFile = File(cacheDir, "download_temp.apk")
|
||||
|
||||
// Check for resumable download
|
||||
@ -241,6 +238,11 @@ class UniversalApkManager(private val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// Bytes already in the temp file have already consumed storage, so
|
||||
// a resume only needs room for the remaining tail. Promotion is a
|
||||
// rename and needs no extra space.
|
||||
checkDiskSpace((expectedSize - existingBytes).coerceAtLeast(0))
|
||||
|
||||
// A temp file that already holds the full asset means the process
|
||||
// died between download and verification. Requesting
|
||||
// "Range: bytes=<size>-" for it would get HTTP 416 forever, so skip
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user