feedback7 G-TOOLS: build-data --refresh fails instead of falling back to an old cache (PR #350 by @siruimei07)

Applied as-is. When --refresh is set, a download that still fails after four attempts throws instead of returning the older cached file, so one build cannot mix a new table with an old one. --offline and a warm cache without --refresh are unchanged. Files already written to the cache stay; generated data/ and the previous report are left in place.

Tests: node --test test/build-data-refresh.test.js — 11 pass, 0 fail.
This commit is contained in:
siruimei07 authored and sganggs committed 2026-10-08 18:42:23 +08:00
1 parent 5662b7ef65
commit 063408e47b
3 files changed
+162 -5

No files matched your search

+3 -2
View File
@@ -8,7 +8,7 @@
//
// Usage: node tools/build-data.mjs [--refresh | --offline] [--out <dir>] [--cache <dir>]
// [--report <file>] [--quiet] [--no-research] [--force]
// --refresh re-download every official file even if cached
// --refresh re-download every official file; fail on download errors even if cached
// --offline never download; fail when a file is missing from the cache
// --out output directory (default: <repo>/data)
// --cache official-data cache directory (default: <repo>/.cache/gamedata)
@@ -127,7 +127,8 @@ async function ensureGamedata(rel) {
if (attempt < 4) await new Promise((r) => setTimeout(r, 500 * attempt));
}
}
if (existsSync(abs)) { warn(`download failed for ${rel}, using stale cache: ${lastErr.message}`); return abs; }
// A refresh cannot mix new downloads with an unverified cache from an earlier run.
if (!OPTS.refresh && existsSync(abs)) { warn(`download failed for ${rel}, using stale cache: ${lastErr.message}`); return abs; }
throw new Error(`cannot obtain ${rel}: ${lastErr && lastErr.message}`);
}