Keep the installed extension when replacing it fails

Co-authored-by: hamenot <hamenot@users.noreply.github.com>
This commit is contained in:
AntsyLich
2026-10-26 02:29:53 +06:00
co-authored by hamenot
parent 3ed83a8d32
commit cdc7d69c92
@@ -24,6 +24,7 @@ import mihon.domain.extension.model.ContentWarning
import mihon.domain.extension.model.ExtensionStore
import tachiyomi.core.common.util.system.logcat
import java.io.File
import java.io.IOException
/**
* Class that handles the loading of the extensions. Supports two kinds of extensions:
@@ -80,12 +81,12 @@ internal object ExtensionLoader {
}
val target = File(getPrivateExtensionDir(context), "${extension.packageName}.$PRIVATE_EXTENSION_EXTENSION")
val staged = File(target.parentFile, "${target.name}.part")
try {
target.delete()
file.copyAndSetReadOnlyTo(target, overwrite = true)
} catch (e: Exception) {
target.delete()
throw e
file.copyAndSetReadOnlyTo(staged, overwrite = true)
if (!staged.renameTo(target)) throw IOException("Unable to replace ${target.name}")
} finally {
staged.delete()
}
if (currentExtension != null) {
ExtensionInstallReceiver.notifyReplaced(context, extension.packageName)