mirror of
https://github.com/mihonapp/mihon.git
synced 2026-11-01 12:35:36 -08:00
Keep the installed extension when replacing it fails
Co-authored-by: hamenot <hamenot@users.noreply.github.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user