fix(recipe): arch 换源幂等(仅 x86),清掉累积 Server 行并补官方兜底 - #394
Merged
ccmywish merged 1 commit intoSep 7, 2026
Conversation
- x86_64 换源前先清空 /etc/pacman.d/mirrorlist 中所有生效 Server 行(含多次换源累积的旧行) - 再写入「新源 + 官方源兜底」,保证每次换源后文件状态确定 - 幂等仅作用于 x86_64;ARM 分支保持原有行为(不清理、仅 prepend),不触及 ARM - 仅作用于 mirrorlist,不影响 pacman.conf 中的 archlinuxcn - 修正官方源地址:上游写的 repo.archlinux.org 域名不存在(DNS 无法解析,官方 mirrorlist 无此项),修正为 Arch 官方推荐的 geo.mirror.pkgbuild.com(自动按地理位置选最近镜像) - 按 doc/50 更新 recipe 时间戳(2026-09-06)、登记贡献者 @yayoinoyume(sauciers 2→3)
|
Hi @yayoinoyume ❤️ 感谢你的贡献!我们将在最少半小时,最多5天内阅读此 PR 并回复你 |
ccmywish
approved these changes
Sep 7, 2026
Contributor
|
👍👍👍 待会儿给你设置为这个 recipe 的 chef Happy changing source~ |
Contributor
Author
|
很高兴我的贡献能被合并!谢谢你的鼓励,我一直梦想着这一天!我会为我的代码负责,祝chsrc越来越好! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联issue
#393
问题描述
1. 换源不幂等,mirrorlist 累积旧 Server 行:
chsrc set arch <源>每次只向/etc/pacman.d/mirrorlistprepend 新的 Server 行、从不清理旧行。多次换源后累积所有历史源,最先命中的可能是旧源(行为不可预期),文件随换源次数线性变脏。2. 官方源地址无效:
Arch Linux 的 Upstream 源地址写死为
https://repo.archlinux.org,但该域名不存在(DNS 解析失败、Arch 官方 mirrorlist 无此项)。任何用户执行chsrc set arch upstream试图恢复官方源,得到的都是无法同步的死地址,pacman -Syy必然失败。3. chsrc reset arch 未实现:
Arch Linux 的
resetfn未声明,chsrc reset arch仅提示“暂未对 arch 实现 reset 功能”,无法恢复官方默认源。方案与实现
1. 换源幂等(仅 x86_64)
os_arch_setsrc在 x86_64 分支内,换源前先执行sed -i '/^Server = /d' /etc/pacman.d/mirrorlist清空所有生效 Server 行(含多次换源累积的旧行),再写入「新源 + 官方源兜底」,保证每次换源后文件状态确定:set arch upstream→ 恰好 1 行(官方源,目标即官方时不重复兜底)/etc/pacman.d/mirrorlist,不影响pacman.conf中的[archlinuxcn]2. 修正官方源地址
repo.archlinux.org(不存在)→geo.mirror.pkgbuild.com(Arch 官方推荐、按地理位置自动选最近镜像)。涉及def_sources的 Upstream 项以及 x86 兜底行(新增OS_Arch_Upstream宏,两处共用)。3. 新增 chsrc reset arch
Arch Linux 原先
resetfn=NULL(prepare 宏 gs)。本次改为gsr并新增os_arch_resetsrc (char *option) { os_arch_setsrc (option); },完全按 chsrc 标准 reset 惯例(与 Ubuntu/Fedora/Ruby 等一致)。chsrc reset arch恢复官方源(geo 一行),复用同一幂等,且不触碰pacman.conf。4. 贡献登记(doc/50)
chef_set_recipe_last_updated→ 2026-09-06chef_set_sauciers2 → 3(新增 @yayoinoyume)chsrc-main.c注册贡献者信息。重要注意:幂等仅针对 x86_64 实现,chsrc arch dish 的 ARM 分支目前是「仅 prepend、无清理、无兜底」。
测试验证结果
1. 基本信息类
chsrc --versionv0.2.7.1 (2026/09/05)chsrc ls archupstream = https://geo.mirror.pkgbuild.comchsrc get archchsrc(无参数)2. 换源类
set arch tuna/ali/tencent/huawei/ustc/bfsu/sjtu-sypacman -Syyu失败set arch upstreamset arch upstream×3 连续set arch https://geo.mirror.pkgbuild.com(自定义=官方)set arch https://mirror.example.org/archlinux.bak生成set arch(不带源名)chsrc reset archset arch <非法源名>镜像站 nonexistent123 不存在+ 提示ls arch,EXIT=4