mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
fix: local builds bundle the addon packs they pin (#1908)
This commit is contained in:
1 parent
8a7022fc14
commit
2ff3ab447d
3 files changed
+57
-1
No files matched your search
@@ -2,6 +2,9 @@ package com.droiddeck.launcher.core
|
||||
|
||||
import android.content.Context
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import com.github.luben.zstd.ZstdOutputStream
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream
|
||||
import java.io.File
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
@@ -54,4 +57,35 @@ class AddonPackTest {
|
||||
installed("b".repeat(64))
|
||||
assertFalse(AddonPack("sample", "", 0L, listOf("tool"), reuseDeviceCopy = false).installed(context))
|
||||
}
|
||||
|
||||
@Test fun localBuildInstallsTheBundledPackWithoutDownloading() {
|
||||
val archive = tarZst("tool" to "x")
|
||||
val pack = AddonPack("sample", Hashes.sha256(archive), archive.length(), listOf("tool"), bundle = { archive.inputStream() })
|
||||
|
||||
assertTrue(pack.await(context))
|
||||
assertEquals("x", pack.file(context, "tool").readText())
|
||||
}
|
||||
|
||||
@Test fun bundledPackWithTheWrongDigestIsRejected() {
|
||||
val archive = tarZst("tool" to "x")
|
||||
val pack = AddonPack("sample", "a".repeat(64), archive.length(), listOf("tool"),
|
||||
bundle = { archive.inputStream() })
|
||||
|
||||
val copy = File(context.cacheDir, "copy.tar.zst")
|
||||
|
||||
assertFalse(pack.bundled(context, copy))
|
||||
assertFalse(copy.exists())
|
||||
}
|
||||
|
||||
private fun tarZst(vararg files: Pair<String, String>): File =
|
||||
File(context.cacheDir, "sample-${System.nanoTime()}.tar.zst").apply {
|
||||
TarArchiveOutputStream(ZstdOutputStream(outputStream())).use { tar ->
|
||||
for ((path, text) in files) {
|
||||
val bytes = text.toByteArray()
|
||||
tar.putArchiveEntry(TarArchiveEntry(path).apply { size = bytes.size.toLong() })
|
||||
tar.write(bytes)
|
||||
tar.closeArchiveEntry()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user