mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 13:55:58 +00:00
fix: an interrupted Linux runtime download resumes instead of starting again (#847)
* fix: an interrupted Linux runtime download resumes instead of starting again installOnce() asked the downloader to resume but always deleted the archive in its finally block, so the next attempt began at zero. The archive is now named after the release version and checksum, a failed download keeps what it fetched, and archives of other releases (and the old fixed name) are removed. A checksum or extraction failure still deletes the file. * test: Downloader resumes a cut-off download from the bytes it kept Starts a socket server that promises the whole file, hangs up part way and then answers a Range request, and checks that the second downloadFile call resumes with the right offset and ends with identical bytes. * fix: a resumed download discards a 206 that does not start where the kept bytes end Downloader appended every 206 response to the partial file without looking at Content-Range. A server or proxy that answers a Range request with a different offset would leave a corrupt file. Check that the range starts at the kept length; otherwise delete the partial file and start again without a Range header. Adds a test with a server that answers the Range request from offset 0. --------- Co-authored-by: ovurrsl <ovurrsl@users.noreply.github.com>
This commit is contained in:
1 parent
98be0838c4
commit
03f1a14e81
4 files changed
+185
-2
No files matched your search
@@ -0,0 +1,36 @@
|
||||
package com.droiddeck.launcher.runtime
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNotEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class LinuxRuntimeArchiveNameTest {
|
||||
private fun release(version: String, sha: String) =
|
||||
LinuxRuntimeInstaller.Release(version, "https://example.invalid/runtime.tar.zst", sha, 1L)
|
||||
|
||||
@Test fun sameReleaseKeepsTheSameName() {
|
||||
val a = LinuxRuntimeInstaller.archiveName(release("r9", "ab".repeat(32)))
|
||||
val b = LinuxRuntimeInstaller.archiveName(release("r9", "ab".repeat(32)))
|
||||
assertEquals(a, b)
|
||||
}
|
||||
|
||||
@Test fun anotherVersionOrChecksumGetsAnotherName() {
|
||||
val base = LinuxRuntimeInstaller.archiveName(release("r9", "ab".repeat(32)))
|
||||
assertNotEquals(base, LinuxRuntimeInstaller.archiveName(release("r10", "ab".repeat(32))))
|
||||
assertNotEquals(base, LinuxRuntimeInstaller.archiveName(release("r9", "cd".repeat(32))))
|
||||
}
|
||||
|
||||
@Test fun nameIsASafeFileNameThatTheCleanupRecognises() {
|
||||
val name = LinuxRuntimeInstaller.archiveName(release("r9/../x y", "AB/CD ".repeat(10)))
|
||||
assertFalse(name.contains('/'))
|
||||
assertFalse(name.contains(' '))
|
||||
assertTrue(name.startsWith("linuxfs"))
|
||||
assertTrue(name.endsWith(".tar.zst"))
|
||||
}
|
||||
|
||||
@Test fun shortOrEmptyChecksumStillMakesAName() {
|
||||
assertEquals("linuxfs-r9-.tar.zst", LinuxRuntimeInstaller.archiveName(release("r9", "")))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user