mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
fix(gog): installs no longer hang on Finishing for large games (#2367)
* fix(gog): list each folder once when checking install paths The case-clash check listed a file's parent folder again for every file, so installing a game with thousands of files stayed on Finishing for a very long time after the download. * fix(gog): check each install path prefix once instead of resolving every file
This commit is contained in:
1 parent
8e02be2440
commit
c177b1eed1
2 files changed
+28
-8
No files matched your search
@@ -65,13 +65,19 @@ internal object GogFiles {
|
||||
fun dir(folder: File): File = inside(folder, ".droiddeck-gog").apply { mkdirs() }
|
||||
fun journal(folder: File): File = File(dir(folder), "operation.json")
|
||||
|
||||
fun inside(root: File, raw: String): File {
|
||||
private fun parts(raw: String): List<String> {
|
||||
val path = raw.replace('\\', '/')
|
||||
val parts = path.split('/')
|
||||
require(path.isNotBlank() && !path.startsWith('/') && ':' !in path && '\u0000' !in path &&
|
||||
path.split('/').none { it.isEmpty() || it == "." || it == ".." }) { "Invalid GOG path: $raw" }
|
||||
parts.none { it.isEmpty() || it == "." || it == ".." }) { "Invalid GOG path: $raw" }
|
||||
return parts
|
||||
}
|
||||
|
||||
fun inside(root: File, raw: String): File {
|
||||
val parts = parts(raw)
|
||||
val base = root.canonicalFile
|
||||
var out = base
|
||||
for (part in path.split('/')) {
|
||||
for (part in parts) {
|
||||
out = File(out, part)
|
||||
require(!Files.isSymbolicLink(out.toPath())) { "GOG path is a symbolic link: $raw" }
|
||||
}
|
||||
@@ -122,21 +128,28 @@ internal object GogFiles {
|
||||
}
|
||||
|
||||
fun validate(files: JSONArray, folder: File) {
|
||||
val base = folder.canonicalFile
|
||||
val paths = HashSet<String>()
|
||||
val components = HashMap<String, String>()
|
||||
val listings = HashMap<File, Map<String, List<String>>>()
|
||||
for (file in files.objects()) {
|
||||
val path = file.getString("path").replace('\\', '/')
|
||||
inside(folder, path)
|
||||
val parts = parts(path)
|
||||
require(!path.startsWith(".droiddeck-", true) && path != StoreGameSidecar.FILE_NAME) { "GOG content overlaps launcher metadata" }
|
||||
require(paths.add(path.lowercase(Locale.ROOT))) { "GOG paths differ only by case: $path" }
|
||||
var parent = folder
|
||||
var parent = base
|
||||
var relative = ""
|
||||
for (part in path.split('/')) {
|
||||
for (part in parts) {
|
||||
relative = if (relative.isEmpty()) part else "$relative/$part"
|
||||
val child = File(parent, part)
|
||||
val previous = components.putIfAbsent(relative.lowercase(Locale.ROOT), relative)
|
||||
require(previous == null || previous == relative) { "GOG directory paths differ only by case: $path" }
|
||||
require(parent.list()?.none { it != part && it.equals(part, true) } != false) { "An existing path differs only by case: $path" }
|
||||
parent = File(parent, part)
|
||||
if (previous == null) {
|
||||
require(!Files.isSymbolicLink(child.toPath())) { "GOG path is a symbolic link: $path" }
|
||||
val existing = listings.getOrPut(parent) { parent.list().orEmpty().groupBy { it.lowercase(Locale.ROOT) } }
|
||||
require(existing[part.lowercase(Locale.ROOT)].orEmpty().all { it == part }) { "An existing path differs only by case: $path" }
|
||||
}
|
||||
parent = child
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,10 +302,17 @@ class GogMaintenanceTest {
|
||||
File(folder, "Game.bin").writeText("original")
|
||||
assertThrows(IllegalArgumentException::class.java) { GogFiles.validate(JSONArray("""[{"path":"game.bin"}]"""), folder) }
|
||||
assertThrows(IllegalArgumentException::class.java) { GogFiles.validate(JSONArray("""[{"path":".droiddeck-store.json"}]"""), folder) }
|
||||
val data = File(folder, "Data").apply { mkdirs() }
|
||||
val installed = JSONArray()
|
||||
for (i in 0 until 2000) { File(data, "Part$i.bin").writeText(""); installed.put(JSONObject().put("path", "Data/Part$i.bin")) }
|
||||
GogFiles.validate(installed, folder)
|
||||
assertThrows(IllegalArgumentException::class.java) { GogFiles.validate(JSONArray("""[{"path":"Data/Part0.bin"},{"path":"Data/part1.bin"}]"""), folder) }
|
||||
val outside = temporary.newFolder()
|
||||
try { Files.createSymbolicLink(File(folder, "link").toPath(), outside.toPath()) }
|
||||
catch (_: java.nio.file.FileSystemException) { return }
|
||||
assertThrows(IllegalArgumentException::class.java) { GogFiles.inside(folder, "link/game.exe") }
|
||||
assertThrows(IllegalArgumentException::class.java) { GogFiles.validate(JSONArray("""[{"path":"Data/Part0.bin"},{"path":"link/game.exe"}]"""), folder) }
|
||||
assertThrows(IllegalArgumentException::class.java) { GogFiles.validate(JSONArray("""[{"path":"a/./file"}]"""), folder) }
|
||||
}
|
||||
|
||||
@Test fun resumedInstallSpaceCountsOnlyFilesStillMissing() {
|
||||
|
||||
Reference in new issue
Block a user