fix: place GOG cloud saves at the location root (#1178)

GOG lists every cloud object as <location name>/<path>. The location name
is not part of the local folder, so Silksong's saves/user1.dat belongs at
default/user1.dat, not default/saves/user1.dat. Strip the segment for local
paths and add it back for HEAD/GET/PUT, cache the location name, and migrate
files written by the old layout without touching files the game wrote.

Co-authored-by: xXJsonDeruloXx <danielhimebauch@gmail.com>
Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-10-25 12:58:54 -04:00
1 parent 0de672f94e
commit 7ef52865d2
5 files changed
+299 -13

No files matched your search

@@ -0,0 +1,76 @@
package com.droiddeck.launcher.stores
import java.io.File
import java.nio.file.Files
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
class CloudSavesMigrationTest {
private val dir = Files.createTempDirectory("cloud-migrate").toFile()
private fun entry(bytes: ByteArray) = CloudPlan.Entry(CloudSaves.md5(bytes), null, 1000L)
private fun nested(name: String, path: String, text: String): File =
File(dir, "$name/$path").apply { parentFile?.mkdirs(); writeText(text) }
@Test fun movesOnlyFilesTheOldBaselineOwns() {
val a = "old save".toByteArray()
val game = "game wrote this".toByteArray()
nested("saves", "a.dat", String(a))
nested("saves", "game.dat", String(game))
val base = mapOf("saves/a.dat" to entry(a))
val result = CloudSaves.migrateNested(dir, "saves", base)!!
assertEquals(1, result.moved)
assertEquals(0, result.cleaned)
assertEquals(String(a), File(dir, "a.dat").readText())
assertEquals(String(game), File(dir, "saves/game.dat").readText())
assertTrue("saves/a.dat" !in result.baseline)
assertEquals(entry(a), result.baseline["a.dat"])
}
@Test fun anIdenticalLeftoverIsRemovedAndItsBaselineKeyRewritten() {
val a = "old save".toByteArray()
File(dir, "a.dat").writeText(String(a))
nested("saves", "a.dat", String(a))
val result = CloudSaves.migrateNested(dir, "saves", mapOf("saves/a.dat" to entry(a)))!!
assertEquals(0, result.moved)
assertEquals(1, result.cleaned)
assertFalse(File(dir, "saves").exists())
assertEquals(entry(a), result.baseline["a.dat"])
assertTrue("saves/a.dat" !in result.baseline)
}
@Test fun aDifferentDestinationKeepsTheGameFileAndTheBaseline() {
val a = "old save".toByteArray()
File(dir, "a.dat").writeText("newer game save")
nested("saves", "a.dat", String(a))
val base = mapOf("saves/a.dat" to entry(a))
val result = CloudSaves.migrateNested(dir, "saves", base)!!
assertEquals(0, result.moved)
assertEquals(0, result.cleaned)
assertEquals("newer game save", File(dir, "a.dat").readText())
assertEquals(String(a), File(dir, "saves/a.dat").readText())
assertEquals(base, result.baseline)
}
@Test fun aSymlinkedAncestorIsNotMigrated() {
val outside = Files.createTempDirectory("cloud-outside").toFile()
File(outside, "a.dat").writeText("outside")
File(dir, "saves").mkdirs()
Files.createSymbolicLink(File(dir, "saves/link").toPath(), outside.toPath())
val result = CloudSaves.migrateNested(dir, "saves",
mapOf("saves/link/a.dat" to entry("outside".toByteArray())))!!
assertEquals(0, result.moved)
assertEquals(0, result.cleaned)
assertTrue(File(outside, "a.dat").isFile)
}
@Test fun aLocationNameThatCanLeaveTheFolderIsRefused() {
nested("saves", "a.dat", "x")
assertNull(CloudSaves.migrateNested(dir, "../saves", emptyMap()))
assertNull(CloudSaves.migrateNested(dir, "..", emptyMap()))
assertNull(CloudSaves.migrateNested(dir, "saves/..", emptyMap()))
}
}
@@ -0,0 +1,52 @@
package com.droiddeck.launcher.stores
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
class GogCloudNamesTest {
private fun files(vararg names: String) = names.map { CloudFile(it, 1000L) }
@Test fun silksongLocationIsDroppedFromThePath() {
val (location, mapped) = gogRelativeNames(
files("saves/user1.dat", "saves/shared.dat", "saves/Restore_Points1/restoreData2.dat"), "saves")
assertEquals("saves", location)
assertEquals(listOf("user1.dat", "shared.dat", "Restore_Points1/restoreData2.dat"), mapped.map { it.name })
}
@Test fun anotherLocationIsFilteredOut() {
val (_, mapped) = gogRelativeNames(files("saves/a.dat", "__default/settings.ini"), "saves")
assertEquals(listOf("a.dat"), mapped.map { it.name })
}
@Test fun theOnlyLocationIsInferredWhenItsNameWasNotCached() {
val (location, mapped) = gogRelativeNames(files("saves/a.dat", "saves/b.dat"), null)
assertEquals("saves", location)
assertEquals(listOf("a.dat", "b.dat"), mapped.map { it.name })
}
@Test fun namesWithoutALocationPrefixAreLeftAlone() {
val (location, mapped) = gogRelativeNames(files("a.dat", "b.dat"), null)
assertNull(location)
assertEquals(listOf("a.dat", "b.dat"), mapped.map { it.name })
}
@Test fun aConfiguredLocationDoesNotYieldToAnotherLocation() {
val (location, mapped) = gogRelativeNames(files("__default/settings.ini"), "saves")
assertEquals("saves", location)
assertTrue(mapped.isEmpty())
}
@Test fun aMixedListingWithOneSubfolderIsLeftAlone() {
val (location, mapped) = gogRelativeNames(files("a.dat", "sub/b.dat"), "saves")
assertNull(location)
assertEquals(listOf("a.dat", "sub/b.dat"), mapped.map { it.name })
}
@Test fun aMissingCachedLocationDoesNotHideUnprefixedNames() {
val (location, mapped) = gogRelativeNames(files("a.dat"), "saves")
assertNull(location)
assertEquals(listOf("a.dat"), mapped.map { it.name })
}
}