mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
fix(storage): let launcher prefixes and Linux system caches be removed (#2867)
This commit is contained in:
1 parent
2ea857a07c
commit
d852b1a4e5
43 files changed
+757
-74
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package com.droiddeck.launcher.storage
|
||||
|
||||
import com.droiddeck.launcher.stores.InstalledStoreGame
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import com.droiddeck.launcher.stores.StoreGameSidecar
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import java.io.File
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34], application = android.app.Application::class)
|
||||
class KeptPrefixRemovalTest {
|
||||
private val compat = File("/rootfs/root/.local/share/Steam/steamapps/compatdata")
|
||||
|
||||
private fun kept(id: String, owner: PrefixOwner) = KeptPrefix(File(compat, id), owner, null, 1L shl 30, "Internal", false)
|
||||
|
||||
private fun report(kept: List<KeptPrefix>, storeFolders: List<File> = emptyList()) = StorageReport(
|
||||
0, 0, 0, emptyMap(), 0, 0, 0, 0, emptyList(), emptyList(), emptyList(), emptyList(), 0, emptyList(), emptyList(), 0,
|
||||
kept, true, storeFolders.map { StoreGameUsage(InstalledStoreGame(StoreGameSidecar(Store.BATTLENET, "pro", "Game", "Game.exe"), it), -1, false) },
|
||||
)
|
||||
|
||||
@Test fun launcherAndUnknownPrefixesCanBeRemoved() {
|
||||
val launcher = kept("2929927072", PrefixOwner.LAUNCHER)
|
||||
val unknown = kept("1234", PrefixOwner.UNKNOWN)
|
||||
val r = report(listOf(launcher, unknown))
|
||||
assertTrue(StorageState.keptRemovable(r, launcher))
|
||||
assertTrue(StorageState.keptRemovable(r, unknown))
|
||||
assertTrue(StorageState.keptRemovable(r, kept("0", PrefixOwner.SHARED)))
|
||||
}
|
||||
|
||||
@Test fun aLauncherPrefixHoldingAnInstalledGameStays() {
|
||||
val bnet = kept("2611429436", PrefixOwner.LAUNCHER)
|
||||
val inside = File(bnet.dir, "pfx/drive_c/Program Files (x86)/Overwatch")
|
||||
assertFalse(StorageState.keptRemovable(report(listOf(bnet), listOf(inside)), bnet))
|
||||
val elsewhere = File(compat, "2611429436-other/Overwatch")
|
||||
assertTrue(StorageState.keptRemovable(report(listOf(bnet), listOf(elsewhere)), bnet))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.droiddeck.launcher.storage
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34], application = android.app.Application::class)
|
||||
class StorageSummaryTest {
|
||||
@Test fun theSavedOverviewReadsBackAsWritten() {
|
||||
val buckets = Bucket.entries.mapIndexed { i, b -> b to (i + 1) * 1_000_000_000L }.toMap()
|
||||
val s = StorageSummary(42, 103L shl 30, 49L shl 30, buckets, 234L shl 20, 3, 1, 7L shl 30, 9L shl 20, 350L shl 20,
|
||||
12, 226L shl 20, 8, 73L shl 20, 0, 0, 105L shl 20, 9L shl 20, 8L shl 30)
|
||||
val back = StorageSummary.fromJson(s.toJson())!!
|
||||
assertEquals(s.toJson(), back.toJson())
|
||||
assertEquals(buckets, back.buckets)
|
||||
assertEquals(s.droiddeck, back.droiddeck)
|
||||
}
|
||||
|
||||
@Test fun anOtherVersionOrDamagedFileReadsAsNone() {
|
||||
assertNull(StorageSummary.fromJson("{\"v\":0}"))
|
||||
assertNull(StorageSummary.fromJson("not json"))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.droiddeck.launcher.storage
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import java.io.File
|
||||
|
||||
class SystemCachesTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
private val now = 10L * 24 * 60 * 60 * 1000
|
||||
private val old = now - SystemCaches.TEMP_IDLE_MS - 1000
|
||||
|
||||
private fun file(path: String, modified: Long) = File(tmp.root, path).apply { parentFile!!.mkdirs(); writeText("x"); setLastModified(modified) }
|
||||
|
||||
@Test fun onlyIdleVisibleTemporaryFilesAreCleared() {
|
||||
file("rootfs/tmp/old.deb", old)
|
||||
file("rootfs/tmp/oldDir/a", old).parentFile!!.setLastModified(old)
|
||||
file("rootfs/tmp/busyDir/a", old)
|
||||
file("rootfs/tmp/busyDir/b", now - 1000).parentFile!!.setLastModified(old)
|
||||
file("rootfs/tmp/.X11-unix/X0", old).parentFile!!.setLastModified(old)
|
||||
file("rootfs/tmp/fresh.log", now)
|
||||
val found = SystemCaches.find(File(tmp.root, "rootfs"), emptyList(), now)
|
||||
assertEquals(listOf("old.deb", "oldDir"), found.getValue(SystemCache.TEMP).map { it.name }.sorted())
|
||||
}
|
||||
|
||||
@Test fun packagesAndSteamCachesAreFound() {
|
||||
file("rootfs/var/cache/apt/archives/git_1_arm64.deb", now)
|
||||
file("rootfs/var/cache/apt/archives/lock", now)
|
||||
file("rootfs/var/cache/apt/archives/partial/perl.deb", now)
|
||||
val steam = File(tmp.root, "rootfs/root/.local/share/Steam")
|
||||
file("rootfs/root/.local/share/Steam/config/htmlcache/Cache/data_0", now)
|
||||
file("rootfs/root/.local/share/Steam/steamapps/corrupt/1_2_ab_corrupt.chunk", now)
|
||||
val found = SystemCaches.find(File(tmp.root, "rootfs"), listOf(steam, File(tmp.root, "missing")), now)
|
||||
assertEquals(listOf("git_1_arm64.deb", "perl.deb"), found.getValue(SystemCache.PACKAGES).map { it.name }.sorted())
|
||||
assertEquals(listOf(File(steam, "config/htmlcache")), found.getValue(SystemCache.STEAM_WEB))
|
||||
assertEquals(listOf(File(steam, "steamapps/corrupt")), found.getValue(SystemCache.STEAM_CORRUPT))
|
||||
}
|
||||
|
||||
@Test fun checkoutsAndTheirWorktreeRecordsAreFound() {
|
||||
val rootfs = File(tmp.root, "rootfs")
|
||||
File(rootfs, "root/DroidDeck/.git/worktrees/dd-pet").mkdirs()
|
||||
file("rootfs/root/dd-pet/.git", now).writeText("gitdir: /root/DroidDeck/.git/worktrees/dd-pet\n")
|
||||
file("rootfs/root/own/.git/HEAD", now)
|
||||
file("rootfs/root/notes/readme", now)
|
||||
file("rootfs/root/bad/.git", now).writeText("gitdir: /root/DroidDeck/.git/worktrees/../../../etc\n")
|
||||
assertEquals(listOf("bad", "dd-pet", "own"), SystemCaches.checkouts(rootfs).map { it.name }.sorted())
|
||||
assertEquals(File(rootfs, "root/DroidDeck/.git/worktrees/dd-pet"), SystemCaches.worktreeRecord(rootfs, File(rootfs, "root/dd-pet")))
|
||||
assertEquals(null, SystemCaches.worktreeRecord(rootfs, File(rootfs, "root/own")))
|
||||
assertEquals(null, SystemCaches.worktreeRecord(rootfs, File(rootfs, "root/bad")))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user