fix: retain desktop removal retry state when cache cleanup fails

This commit is contained in:
xXJsonDeruloXx committed 2026-10-22 07:46:05 -04:00
1 parent 920dc17596
commit dca5466aa9
2 files changed
+24 -3

No files matched your search

@@ -134,12 +134,13 @@ object DesktopCatalog {
internal fun discardDesktopInstall(context: Context) {
val entry = interrupted(context).firstOrNull { it.id == DESKTOP_ID }
val journal = journal(LinuxRuntime.rootDir(context), DESKTOP_ID)
check(!journal.exists() || journal.delete()) { "Could not clear desktop installation" }
entry?.let {
val download = downloadFile(context, it)
download.delete()
File(download.path + ".resume.properties").delete()
for (file in listOf(download, File(download.path + ".resume.properties"))) {
check(!file.exists() || file.delete()) { "Could not remove desktop download ${file.name}" }
}
}
check(!journal.exists() || journal.delete()) { "Could not clear desktop installation" }
}
fun install(context: Context, entry: Entry, listener: LinuxRuntimeInstaller.ProgressListener?): String? = synchronized(installLock) {
@@ -87,6 +87,26 @@ class DesktopRemovalTest {
assertTrue(Files.isSymbolicLink(desktop.toPath()))
}
@Test fun failedDownloadCleanupKeepsTheInstallRecordSoRemovalCanRetry() {
val entry = DesktopCatalog.desktopEntry(context)
val download = File(context.cacheDir, "pkg-${entry.id}-${entry.sha256.take(12)}.download")
for (blocked in listOf(download, File(download.path + ".resume.properties"))) {
desktopFiles()
journal.writeText(DesktopCatalog.entryJson(entry).toString())
blocked.mkdirs()
val blocker = File(blocked, "blocker").apply { writeText("fixture") }
assertNotNull(DesktopCatalog.removeDesktop(context, listener))
assertTrue(journal.exists())
assertTrue(pending.exists())
assertTrue(blocker.delete())
assertNull(DesktopCatalog.removeDesktop(context, listener))
assertFalse(blocked.exists())
assertFalse(journal.exists())
assertFalse(pending.exists())
}
}
private fun file(path: String, text: String) = File(root, path).apply { parentFile!!.mkdirs(); writeText(text) }
private fun desktopFiles(): File {