Always include boot image when processing tar

Credits: @BlackMesa123

Fix #7132, close #7133
This commit is contained in:
topjohnwu 2023-07-09 02:04:42 -07:00
parent 4856da1584
commit 4caed73fe0

View File

@ -232,7 +232,19 @@ abstract class MagiskInstallImpl protected constructor(
val boot = installDir.getChildFile("boot.img") val boot = installDir.getChildFile("boot.img")
val initBoot = installDir.getChildFile("init_boot.img") val initBoot = installDir.getChildFile("init_boot.img")
val recovery = installDir.getChildFile("recovery.img") val recovery = installDir.getChildFile("recovery.img")
if (Config.recovery && recovery.exists() && boot.exists()) {
fun ExtendedFile.copyToTar() {
newInputStream().use {
tarOut.putNextEntry(newTarEntry(name, length()))
it.copyTo(tarOut)
}
delete()
}
// Patch priority: recovery > init_boot > boot
return when {
recovery.exists() -> {
if (boot.exists()) {
// Repack boot image to prevent auto restore // Repack boot image to prevent auto restore
arrayOf( arrayOf(
"cd $installDir", "cd $installDir",
@ -243,21 +255,17 @@ abstract class MagiskInstallImpl protected constructor(
"./magiskboot cleanup", "./magiskboot cleanup",
"rm -f new-boot.img", "rm -f new-boot.img",
"cd /").sh() "cd /").sh()
boot.newInputStream().use { boot.copyToTar()
tarOut.putNextEntry(newTarEntry("boot.img", boot.length())) }
it.copyTo(tarOut) recovery
}
initBoot.exists() -> {
if (boot.exists())
boot.copyToTar()
initBoot
} }
boot.delete()
// Install to recovery
return recovery
} else {
return when {
initBoot.exists() -> initBoot
boot.exists() -> boot boot.exists() -> boot
else -> { else -> throw NoBootException()
throw NoBootException()
}
}
} }
} }