镜像自地址
https://github.com/JGZYES/ParlzPackageManger.git
已同步 2026-09-11 05:42:44 +08:00
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.
这个提交包含在:
+20
-24
@@ -927,34 +927,30 @@ static int cmd_setting(int argc, char **argv) {
|
|||||||
const char *loc = argv[1];
|
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; }
|
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();
|
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);
|
mkdir_p_local(langdir);
|
||||||
char out[1400];
|
char out[1400];
|
||||||
snprintf(out, sizeof(out), "%s/%s.pjson", langdir, loc);
|
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));
|
pmm_error("%s", pmm_tr_fmt("msg.err.download-failed", loc));
|
||||||
mirrors_free(ml); return 1;
|
mirrors_free(ml); return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户