setting lang: try every registry mirror, not just the first, when fetching a pack

The default/priority-1 mirror (sz.pmm.parlz.com) returns 404 for /mirror/lang
(and even for its registry root), so 'pmm setting lang <loc>' always failed even
though the backup mirror (pmm.parlz.com) serves the pack. Iterate all mirrors in
priority order and stop at the first that serves the .pjson.
这个提交包含在:
JGZYES
2026-09-05 15:06:19 +08:00
父节点 b7f952e032
当前提交 7d13e07232
+20 -24
查看文件
@@ -927,34 +927,30 @@ static int cmd_setting(int argc, char **argv) {
const char *loc = argv[1];
if (strchr(loc, '/') || strchr(loc, '\\') || strstr(loc, "..")) { pmm_error("%s", pmm_tr_fmt("msg.err.invalid-locale", loc)); return 1; }
/* pick a registry base for the language pack */
/* Try every registry mirror in priority order; a pack may only be reachable
* on a secondary mirror. Language packs live under {host}/mirror/lang/, NOT
* the registry base {host}/mirror/packages, so swap the trailing "/packages"
* (if present) for "/lang". */
MirrorList *ml = mirrors_load();
const char *base = NULL;
for (int i = 0; i < ml->count; i++)
if (ml->items[i].registry && *ml->items[i].registry) { base = ml->items[i].registry; break; }
if (!base) { pmm_error("%s", pmm_tr("msg.err.no-registry-mirror")); mirrors_free(ml); return 1; }
/* Language packs live under {host}/mirror/lang/, NOT under the registry
* base {host}/mirror/packages. Derive it by swapping the trailing
* "/packages" (if present) for "/lang". */
char base2[2048];
snprintf(base2, sizeof(base2), "%s", base);
{
size_t bl = strlen(base2);
static const char *pkgsuf = "/packages";
size_t pl = strlen(pkgsuf);
if (bl >= pl && strcmp(base2 + bl - pl, pkgsuf) == 0) {
strcpy(base2 + bl - pl, "/lang"); /* .../mirror/packages -> .../mirror/lang */
} else {
snprintf(base2 + bl, sizeof(base2) - bl, "/lang");
}
}
char url[2048];
snprintf(url, sizeof(url), "%s/%s.pjson", base2, loc);
mkdir_p_local(langdir);
char out[1400];
snprintf(out, sizeof(out), "%s/%s.pjson", langdir, loc);
if (http_download(url, out) != 0) {
char url[2048], base2[2048];
int got = 0;
for (int i = 0; i < ml->count; i++) {
if (!ml->items[i].registry || !*ml->items[i].registry) continue;
snprintf(base2, sizeof(base2), "%s", ml->items[i].registry);
size_t bl = strlen(base2);
static const char *pkgsuf = "/packages";
size_t pl = strlen(pkgsuf);
if (bl >= pl && strcmp(base2 + bl - pl, pkgsuf) == 0)
strcpy(base2 + bl - pl, "/lang"); /* .../mirror/packages -> .../mirror/lang */
else
snprintf(base2 + bl, sizeof(base2) - bl, "/lang");
snprintf(url, sizeof(url), "%s/%s.pjson", base2, loc);
if (http_download(url, out) == 0) { got = 1; break; }
}
if (!got) {
pmm_error("%s", pmm_tr_fmt("msg.err.download-failed", loc));
mirrors_free(ml); return 1;
}