Skip to content

fix: 拒绝复用失败的版本状态 - #5222

Closed
eyaeya wants to merge 1 commit into
vernesong:devfrom
eyaeya:net/version-state-refresh
Closed

eyaeya wants to merge 1 commit into
vernesong:devfrom
eyaeya:net/version-state-refresh

Conversation

@eyaeya

@eyaeya eyaeya commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Dependency chain

推荐合并顺序:本 PR 可独立合并;若同时处理系统包管理器锁状态,请优先或并行合并 #5217。两者触及相邻更新路径,但行为边界不同。

问题现象

核心版本检测或 OpenClash 包版本检测失败时,旧的 /tmp/clash_last_version/tmp/openclash_last_version 仍会留在本机。随后 openclash_core.shopenclash_update.sh 只看固定版本文件是否存在,可能把旧版本状态当成本轮检测结果继续进入更新判断。

根因

clash_version.shopenclash_version.sh 调用 DOWNLOAD_FILE_CURL 后没有检查返回码,也没有在失败时清理旧版本状态文件。调用方也只判断 fixed last_version 文件是否存在,没有区分“本轮检测成功”和“旧文件还在”。

证据

  • clash_version.sh 原先直接调用 DOWNLOAD_FILE_CURL "$DOWNLOAD_URL" "$DOWNLOAD_FILE" "$DOWNLOAD_FILE" 后释放锁并退出。
  • openclash_version.sh 原先只在 $? -eq 0 时处理版本内容,失败时旧 /tmp/openclash_last_version 仍保留。
  • openclash_core.sh 原先只判断 /tmp/clash_last_version 是否存在。
  • openclash_update.sh 原先只判断 /tmp/openclash_last_version 是否存在。
  • tests/openclash_version_state_test.sh 覆盖了“已有旧版本文件 + 本轮下载失败”的场景,并验证调用方在版本刷新失败后不会继续进入后续下载路径。

修复方案

  • 版本检测脚本记录 DOWNLOAD_FILE_CURL 返回码。
  • 返回 02 时按现有成功/304 缓存语义继续。
  • 其他失败返回时删除对应 last_version 文件并返回非 0。
  • openclash_core.shopenclash_update.sh 同时检查版本脚本退出码和 last_version 文件存在性。

为什么没有扩大修复范围

没有修改 openclash_curl.sh 的通用下载实现,因为它已经使用 .download.$$ 临时文件避免半截下载覆盖目标。本 PR 只修复调用方对“失败但旧状态仍存在”的判断问题,不改变 ETag、304、CDN、release asset 或系统 feed 行为。

与已有开启态 PR 的关系

验证命令和结果

均已通过:

bash -n luci-app-openclash/root/usr/share/openclash/*.sh
bash -n tests/*.sh
tests/openclash_version_state_test.sh
tests/openclash_curl_test.sh
for t in tests/*.sh; do "$t"; done
git diff --check
rg -n '^(<<<<<<<|=======|>>>>>>>)' luci-app-openclash tests

最后一条无命中。

剩余风险

未做 live router 验证。该修复只改变版本检测失败后的状态处理;如果网络临时失败,UI/更新脚本会要求重新检测版本,而不是继续复用旧 last_version。

@eyaeya

eyaeya commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

这个拆分 PR 已被新的合并版 PR 取代:#5231

原因:#5217#5218#5222 都属于更新/版本状态健壮性修复,并且按任意顺序合并时会在 luci-app-openclash/root/usr/share/openclash/openclash_version.sh 产生真实冲突。新的合并版 PR 保留了本 PR 的行为,同时把相关冲突点一次性整理成单个 reviewer 友好的提交。

已在合并版 PR 中验证:

  • focused tests
  • 相关 shell bash -n
  • git diff --check
  • conflict marker scan
  • 多轮对抗式复核,最终无修改点

@eyaeya eyaeya closed this Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant