Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c8d4c508d |
No files matched your search
@@ -136,7 +136,7 @@ internal object GogContent {
|
||||
val file = JSONObject().put("path", path).put("size", size).put("directory", directory)
|
||||
.put("md5", entry.optString("md5").ifBlank { entry.optString("hash") }.takeIf { it.matches(Regex("[a-fA-F0-9]{32}")) }.orEmpty())
|
||||
.put("sha256", entry.optString("sha256")).put("chunks", chunks).put("product", product)
|
||||
.put("offset", entry.optLong("offset")).put("remotePath", entry.optString("url").substringBefore('?'))
|
||||
.put("offset", entry.optLong("offset")).put("remotePath", remotePath(entry.optString("url"), build.generation))
|
||||
val position = if (build.generation == 2) overlayPositions.putIfAbsent(path, files.length()) else null
|
||||
if (position == null) files.put(file) else {
|
||||
require(files.getJSONObject(position).getBoolean("directory") == directory)
|
||||
@@ -149,6 +149,10 @@ internal object GogContent {
|
||||
branch = build.branch, language = resolvedLanguage, manifest = sanitize(manifest), files = files, products = products.toList(), verified = true)
|
||||
}
|
||||
|
||||
fun remotePath(url: String, generation: Int): String = url.substringBefore('?').let {
|
||||
if (generation == 1 && !it.startsWith("https://")) it.substringAfterLast('/') else it
|
||||
}
|
||||
|
||||
fun languageSelected(list: List<String>, selected: String): Boolean = list.any { it.equals("Neutral", true) } || StoreLanguage.depotMatchesResolved(list.toTypedArray(), selected)
|
||||
|
||||
fun cdnPath(hash: String): String {
|
||||
|
||||
@@ -270,7 +270,8 @@ pub fn run(req: &GogRequest, cancel: &AtomicBool, events: &dyn GogEvents) -> Gog
|
||||
let offset = num(file, "offset");
|
||||
let remote = text(file, "remotePath");
|
||||
let endpoints = if remote.starts_with("https://") { vec![remote.to_string()] } else { urls(&plan["links"], text(file, "product"), remote.trim_start_matches('/')) };
|
||||
transfer.fetch(&endpoints, Some((offset, offset + num(file, "size") - 1)), &stage, num(file, "size"))?;
|
||||
transfer.fetch(&endpoints, Some((offset, offset + num(file, "size") - 1)), &stage, num(file, "size"))
|
||||
.map_err(|e| format!("{e} file={} remote={remote}", text(file, "path")))?;
|
||||
} else {
|
||||
let mut output = OpenOptions::new().create(true).truncate(false).read(true).write(true).open(&stage).map_err(|e| e.to_string())?;
|
||||
let mut offset = 0u64;
|
||||
@@ -286,7 +287,8 @@ pub fn run(req: &GogRequest, cancel: &AtomicBool, events: &dyn GogEvents) -> Gog
|
||||
std::io::copy(&mut source.take(old.size), &mut output).map_err(|e| e.to_string())?;
|
||||
reused += old.size;
|
||||
} else {
|
||||
download_chunk(&mut transfer, &plan["links"], text(file, "product"), chunk, &stage.with_extension("packed"), &mut output)?;
|
||||
download_chunk(&mut transfer, &plan["links"], text(file, "product"), chunk, &stage.with_extension("packed"), &mut output)
|
||||
.map_err(|e| format!("{e} file={}", text(file, "path")))?;
|
||||
}
|
||||
offset += num(chunk, "size");
|
||||
}
|
||||
@@ -462,6 +464,20 @@ mod tests {
|
||||
assert_eq!(server.bytes.load(Ordering::Relaxed), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn failed_fetches_name_the_file_and_remote_path() {
|
||||
let temp = Temp::new(); let missing = Server::new(HashMap::new(), true);
|
||||
let ranged = json!([{"path":"support/1/setup.exe", "size":4, "chunks":[], "product":"1", "remotePath":"main.bin", "offset":0}]);
|
||||
let result = execute(&temp.0, ranged, json!([]), &missing);
|
||||
assert!(result.link_expiry, "{}", result.error);
|
||||
assert_eq!(result.error, "HTTP 404 file=support/1/setup.exe remote=main.bin");
|
||||
let (a, _, _) = chunk(b"data");
|
||||
let chunked = json!([{"path":"Data/pack.dat", "size":4, "md5":md5_hex(b"data"), "chunks":[a], "product":"1"}]);
|
||||
let result = execute(&temp.0, chunked, json!([]), &missing);
|
||||
assert!(result.link_expiry, "{}", result.error);
|
||||
assert_eq!(result.error, "HTTP 404 file=Data/pack.dat");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bad_chunks_never_replace_original_and_expired_links_are_reported() {
|
||||
let temp = Temp::new(); fs::write(temp.0.join("game"), b"old!").unwrap();
|
||||
|
||||
@@ -270,9 +270,20 @@ class GogMaintenanceTest {
|
||||
val game = snapshot.files.getJSONObject(1)
|
||||
assertEquals("Data/World/Levels/Raycap/Raycap.snd", game.getString("path"))
|
||||
assertEquals(384206096L, game.getLong("offset"))
|
||||
assertEquals("1207658940/main.bin", game.getString("remotePath"))
|
||||
assertEquals("main.bin", game.getString("remotePath"))
|
||||
assertEquals("main.bin", support.getString("remotePath"))
|
||||
assertTrue(requested.drop(1).all { "/1207658940/windows/31847977/" in it })
|
||||
GogFiles.validate(snapshot.files, temporary.newFolder())
|
||||
val secureLink = "https://cdn.example.invalid/token=abc/content-system/v1/depots/1207658940/windows/31847977/"
|
||||
assertEquals(listOf("${secureLink}main.bin"), GogFallback.endpoints(JSONObject().put("1207658940", JSONArray().put(secureLink)),
|
||||
game.getString("product"), game.getString("remotePath")))
|
||||
}
|
||||
|
||||
@Test fun onlyRelativeGenerationOneUrlsAreReducedToTheirFileName() {
|
||||
assertEquals("main.bin", GogContent.remotePath("1207663863/main.bin?expires=1", 1))
|
||||
assertEquals("https://cdn.example.invalid/1207663863/main.bin", GogContent.remotePath("https://cdn.example.invalid/1207663863/main.bin?expires=1", 1))
|
||||
assertEquals("1207663863/main.bin", GogContent.remotePath("1207663863/main.bin", 2))
|
||||
assertEquals("", GogContent.remotePath("", 1))
|
||||
}
|
||||
|
||||
@Test fun multipartPatchNamesVersionsLanguageAndChecksumsSurviveParsing() {
|
||||
|
||||
Reference in new issue
Block a user