mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-25 07:46:01 +00:00
fix(gog): skip saves GOG Cloud marks deleted (#3025)
* fix(gog): skip saves GOG Cloud marks deleted GOG keeps a deleted cloud save in the listing as an empty gzip object (hash aadd86936a80ee8a369579c3926f1b3c). The listing was read as plain names without hashes, so every deleted save was downloaded again as an empty file. Ask for the JSON listing, keep each object's hash, treat deletion markers as absent, and only send a marked save back once it changed locally. Local files are never removed. * docs: credit gogdl and Lutris for the GOG cloud deletion marker
This commit is contained in:
1 parent
ae47876386
commit
8bb1895702
7 files changed
+89
-10
No files matched your search
@@ -36,13 +36,14 @@ object CloudPlan {
|
||||
return Plan(transfer, conflicts, same)
|
||||
}
|
||||
|
||||
fun up(local: Map<String, Local>, remote: Map<String, Remote>, baseline: Map<String, Entry>?): Plan {
|
||||
fun up(local: Map<String, Local>, remote: Map<String, Remote>, baseline: Map<String, Entry>?, deleted: Set<String> = emptySet()): Plan {
|
||||
if (baseline == null) return Plan(emptyList(), emptyList(), emptyList(), refused = "no-baseline")
|
||||
val transfer = ArrayList<String>(); val conflicts = ArrayList<String>(); val same = ArrayList<String>()
|
||||
for ((name, l) in local) {
|
||||
val r = remote[name]
|
||||
val b = baseline[name]
|
||||
when {
|
||||
r == null && name in deleted && !localChanged(l, b) -> Unit
|
||||
r == null -> transfer += name
|
||||
same(l, r) -> same += name
|
||||
localChanged(l, b) && cloudChanged(r, b) -> conflicts += name
|
||||
|
||||
@@ -430,17 +430,20 @@ object CloudSaves {
|
||||
|
||||
internal fun md5(data: ByteArray): String = MessageDigest.getInstance("MD5").digest(data).joinToString("") { "%02x".format(it) }
|
||||
|
||||
private fun remote(cloud: CloudTransport, wanted: (String) -> Boolean): Map<String, CloudFile> {
|
||||
private class Listing(val live: Map<String, CloudFile>, val deleted: Set<String>)
|
||||
|
||||
private fun remote(cloud: CloudTransport, wanted: (String) -> Boolean): Listing {
|
||||
val files = cloud.list()
|
||||
val pool = Executors.newFixedThreadPool(PARALLEL, com.droiddeck.launcher.stores.download.DownloadQueue.workerFactory("cloud"))
|
||||
for (f in files) if (wanted(f.name)) pool.execute { runCatching { cloud.details(f) } }
|
||||
pool.shutdown(); pool.awaitTermination(2, TimeUnit.MINUTES)
|
||||
return files.associateBy { it.name }
|
||||
val (gone, live) = files.partition(cloud::deleted)
|
||||
return Listing(live.associateBy { it.name }, gone.mapTo(HashSet()) { it.name })
|
||||
}
|
||||
|
||||
internal fun downWith(context: Context, store: Store, id: String, dir: File, cloud: CloudTransport, force: Boolean, claim: () -> Boolean = { true }): Result {
|
||||
val files = localFiles(dir).filterKeys(cloud::wants)
|
||||
val remote = remote(cloud) { it in files }
|
||||
val remote = remote(cloud) { it in files }.live
|
||||
val local = files.mapValues { CloudPlan.Local(md5(it.value)) }
|
||||
val key = scope(store, id, dir)
|
||||
val base = baseline(context, store, key)
|
||||
@@ -498,9 +501,10 @@ object CloudSaves {
|
||||
val base = baseline(context, store, key) ?: return Result("skipped", 0, 0, "no-baseline")
|
||||
val files = localFiles(dir).filterKeys(cloud::wants).let { all -> if (cloud is UbisoftCloudTransport) all.filterValues(::markUbisoftSave) else all }
|
||||
if (files.isEmpty()) return Result("skipped", 0, 0, "nothing-local")
|
||||
val remote = remote(cloud) { it in files }
|
||||
val listing = remote(cloud) { it in files }
|
||||
val remote = listing.live
|
||||
val local = files.mapValues { CloudPlan.Local(md5(it.value)) }
|
||||
val planned = CloudPlan.up(local, remote.mapValues { CloudPlan.Remote(it.value.md5, it.value.modifiedMs) }, base)
|
||||
val planned = CloudPlan.up(local, remote.mapValues { CloudPlan.Remote(it.value.md5, it.value.modifiedMs) }, base, listing.deleted)
|
||||
val alike = alike(cloud, planned.conflicts, local, remote)
|
||||
val plan = settled(planned, alike)
|
||||
val saved = savedConflicts(context, store, key).filter { it !in alike && it !in plan.same }
|
||||
@@ -547,7 +551,7 @@ object CloudSaves {
|
||||
send = send.filter { it in stamped }
|
||||
for ((name, t) in stamped) if (t > 0) files[name]?.setLastModified(t)
|
||||
}
|
||||
val after = if (send.all { cloud.committed(it) != null }) emptyMap() else remote(cloud) { it in send && cloud.committed(it) == null }
|
||||
val after = if (send.all { cloud.committed(it) != null }) emptyMap() else remote(cloud) { it in send && cloud.committed(it) == null }.live
|
||||
for (name in send) {
|
||||
val r = cloud.committed(name) ?: after[name]
|
||||
next[name] = CloudPlan.Entry(sentMd5.getValue(name), r?.md5, r?.modifiedMs ?: stamped[name] ?: -1L)
|
||||
|
||||
@@ -31,6 +31,7 @@ interface CloudTransport {
|
||||
val contentDigests: Boolean get() = true
|
||||
fun committed(name: String): CloudFile? = null
|
||||
fun wants(name: String): Boolean = true
|
||||
fun deleted(file: CloudFile): Boolean = false
|
||||
fun list(): List<CloudFile>
|
||||
fun details(file: CloudFile) {}
|
||||
fun get(file: CloudFile): Pair<ByteArray, Long>
|
||||
@@ -252,6 +253,8 @@ private fun gzipFile(src: File, dst: File): GzipFile {
|
||||
}
|
||||
}
|
||||
|
||||
internal const val GOG_DELETED_MD5 = "aadd86936a80ee8a369579c3926f1b3c"
|
||||
|
||||
internal const val GOG_CLOUD_UA = "GOGGalaxyCommunicationService/2.0.13.27 (Windows_32bit) dont_sync_marker/true installation_source/gog"
|
||||
|
||||
/** GOG Galaxy parses `X-Object-Meta-LocalLastModified`; objects without it fail as "invalid data". */
|
||||
@@ -276,8 +279,11 @@ class GogCloud(
|
||||
|
||||
private fun cloudKey(name: String) = key((prefix ?: "") + name)
|
||||
|
||||
override fun deleted(file: CloudFile): Boolean = file.md5.equals(GOG_DELETED_MD5, ignoreCase = true)
|
||||
|
||||
override fun list(): List<CloudFile> {
|
||||
val c = open(base, "GET", token, ua)
|
||||
c.setRequestProperty("Accept", "application/json")
|
||||
val code = c.responseCode
|
||||
if (code == 404) { c.disconnect(); return emptyList() }
|
||||
if (code !in 200..299) {
|
||||
@@ -300,7 +306,7 @@ class GogCloud(
|
||||
lm > 0 -> lm * 1000
|
||||
iso > 0 -> iso
|
||||
else -> -1L
|
||||
})
|
||||
}, o.optString("hash").trim().ifEmpty { null })
|
||||
}
|
||||
} else {
|
||||
text.lines().map { it.trim() }.filter { it.isNotEmpty() }.map { CloudFile(it, -1L) }
|
||||
|
||||
Reference in new issue
Block a user