feat(desktop): add desktop uninstall and legacy LXQt cleanup (#493)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-10 10:59:32 -04:00
1 parent 79d92111e4
commit 67a9ea2f42
28 files changed
+728 -25

No files matched your search

@@ -23,6 +23,10 @@ class DesktopCatalogTest {
assertFalse(DesktopCatalog.desktopInstalled(root))
marker.writeText("${BuildConfig.DESKTOP_KDE_TAG}\n")
assertTrue(DesktopCatalog.desktopInstalled(root))
val pending = File(root, DesktopRemoval.PENDING).apply { writeText(BuildConfig.DESKTOP_KDE_TAG) }
assertFalse(DesktopCatalog.desktopInstalled(root))
pending.delete()
assertTrue(DesktopCatalog.desktopInstalled(root))
kwin.delete()
assertFalse(DesktopCatalog.desktopInstalled(root))
}
@@ -0,0 +1,79 @@
package com.droiddeck.launcher.runtime
import java.io.File
import java.nio.file.Files
import org.junit.After
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
class DesktopFileRemovalTest {
private lateinit var dir: File
private lateinit var root: File
@Before fun setup() { dir = Files.createTempDirectory("desktop-removal").toFile(); root = File(dir, "linuxfs").apply { mkdirs() } }
@After fun cleanup() { RuntimeFileTree.delete(dir, null) }
private fun file(path: String, data: String) = File(root, path).apply { parentFile.mkdirs(); writeText(data) }
private fun entry(path: String, file: File) = DesktopFileRemoval.Entry("F", file.length(), DesktopFileRemoval.sha(file), path)
@Test fun removesUnchangedFilesAndEmptyParentsButPreservesUserDataAndSharedFiles() {
val desktop = file("usr/share/plasma/only/asset", "desktop")
val shared = file("usr/lib/shared.so", "shared")
val custom = file("usr/share/plasma/custom", "user")
val home = file("root/.local/share/Steam/game", "game")
val result = DesktopFileRemoval.remove(root, listOf(entry("usr/share/plasma/only/asset", desktop), entry("usr/lib/shared.so", shared), entry("root/.local/share/Steam/game", home)), setOf("usr/lib/shared.so"))
assertEquals(1, result.removed)
assertEquals(7L, result.bytes)
assertFalse(desktop.parentFile.exists())
assertEquals("shared", shared.readText())
assertEquals("user", custom.readText())
assertEquals("game", home.readText())
}
@Test fun preservesChangesIncludingSameLengthEditsAndSymlinkReplacement() {
val file = file("usr/bin/desktop", "before")
val expected = entry("usr/bin/desktop", file)
file.writeText("edited")
val target = file("root/private", "data")
val link = File(root, "usr/bin/link")
Files.createSymbolicLink(link.toPath(), target.toPath())
val result = DesktopFileRemoval.remove(root, listOf(expected, DesktopFileRemoval.Entry("L", 0, "/usr/bin/original", "usr/bin/link")), emptySet())
assertEquals(0, result.removed)
assertEquals("edited", file.readText())
assertTrue(Files.isSymbolicLink(link.toPath()))
}
@Test fun neverFollowsParentsEvenWhenTheyPointInsideRootAndOnlyUnlinksRecordedLinks() {
val keep = file("root/private/asset", "desktop")
File(root, "usr/share").mkdirs()
Files.createSymbolicLink(File(root, "usr/share/plasma").toPath(), File(root, "root/private").toPath())
val dangling = File(root, "usr/share/dangling")
Files.createSymbolicLink(dangling.toPath(), File("/missing").toPath())
val result = DesktopFileRemoval.remove(root, listOf(entry("usr/share/plasma/asset", keep), DesktopFileRemoval.Entry("L", 0, "/missing", "usr/share/dangling")), emptySet())
assertEquals(1, result.removed)
assertEquals("desktop", keep.readText())
assertFalse(Files.exists(dangling.toPath(), java.nio.file.LinkOption.NOFOLLOW_LINKS))
}
@Test fun rejectsTraversalAbsolutePathsAndUserHome() {
for (path in listOf("../etc/x", "/etc/x", "usr/../../x", "usr/./x", "usr//x", "root/x", "opt/appimages/x"))
assertNull(path, DesktopFileRemoval.safeFile(root, path))
}
@Test fun interruptedRemovalIsIdempotentAndRetriesRemainingFiles() {
val one = file("usr/bin/one", "one")
val two = file("usr/bin/two", "two")
val entries = listOf(entry("usr/bin/one", one), entry("usr/bin/two", two))
try { DesktopFileRemoval.remove(root, entries.asSequence().constrainOnce().asIterable(), emptySet()) { throw IllegalStateException("process ended") }; fail() }
catch (_: IllegalStateException) { }
assertFalse(one.exists())
assertTrue(two.exists())
assertEquals(1, DesktopFileRemoval.remove(root, entries, emptySet()).removed)
assertEquals(0, DesktopFileRemoval.remove(root, entries, emptySet()).removed)
}
@Test fun readsOnlyRuntimePackageFilesAndRefusesMissingOwnership() {
try { DesktopFileRemoval.runtimeFiles(root); fail() } catch (_: java.io.IOException) { }
file("var/lib/pacman/local/base-1/files", "%FILES%\nusr/\nusr/bin/\nusr/bin/gamescope\n\n%BACKUP%\netc/config\n")
assertEquals(setOf("usr/bin/gamescope"), DesktopFileRemoval.runtimeFiles(root))
}
}
@@ -0,0 +1,63 @@
package com.droiddeck.launcher.runtime
import com.droiddeck.launcher.session.SessionPhase
import com.droiddeck.launcher.session.SessionState
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import org.junit.Assert.*
import org.junit.Test
class DesktopMaintenanceTest {
@Test(timeout = 15000) fun reservationBlocksRuntimeChangesAndFollowersSurviveScreenRecreation() {
SessionState.running = false
SessionState.phase = SessionPhase.IDLE
val operation = LinuxRuntimeInstaller.beginMaintenance(null, "Removing desktop")!!
assertTrue(LinuxRuntimeInstaller.isBusy())
assertTrue(LinuxRuntimeInstaller.isMaintaining())
assertFalse(LinuxRuntimeInstaller.isRemoving())
assertFalse(LinuxRuntimeInstaller.install(null, null, null))
assertNull(LinuxRuntimeInstaller.beginMaintenance(null, "other"))
assertNull(LinuxRuntimeInstaller.beginUninstall(null, java.io.File("unused")))
val entered = CountDownLatch(1)
val release = CountDownLatch(1)
val worker = Thread {
assertTrue(operation.run(null) { progress ->
progress.onProgress("Removing desktop", 30)
entered.countDown()
assertTrue(release.await(5, TimeUnit.SECONDS))
progress.onProgress("Desktop removed", 100)
null
})
}
worker.start()
try {
assertTrue(entered.await(5, TimeUnit.SECONDS))
val following = CountDownLatch(1)
val follower = Thread {
assertEquals(true, LinuxRuntimeInstaller.attach { stage, _ ->
if (stage == "Removing desktop") following.countDown()
})
}
follower.start()
assertTrue(following.await(5, TimeUnit.SECONDS))
release.countDown()
worker.join(5000); follower.join(5000)
assertFalse(LinuxRuntimeInstaller.isBusy())
} finally { release.countDown(); worker.join(5000) }
}
@Test(timeout = 15000) fun refusesActiveOrStartingSessionsAndReportsFailureWithoutRetainingTheReservation() {
SessionState.phase = SessionPhase.STARTING_GUEST
assertNull(LinuxRuntimeInstaller.beginMaintenance(null, "Removing desktop"))
SessionState.phase = SessionPhase.IDLE
SessionState.running = true
assertNull(LinuxRuntimeInstaller.beginMaintenance(null, "Removing desktop"))
SessionState.running = false
val operation = LinuxRuntimeInstaller.beginMaintenance(null, "Removing desktop")!!
assertFalse(operation.run(null) { "cannot unlink" })
assertEquals("cannot unlink", LinuxRuntimeInstaller.removalError())
assertFalse(LinuxRuntimeInstaller.isBusy())
assertTrue(LinuxRuntimeInstaller.beginMaintenance(null, "retry")!!.run(null) { null })
assertNull(LinuxRuntimeInstaller.removalError())
}
}