Repository navigation
fix(wpm): key download cache by version and artifact hash (issue #1154) - #1157
Merged
Merged
Conversation
The artifact cache file name was '<pkg>.<ext>', keyed by package name alone. After an index revision bumped a package version (new URL and sha256), 'wpm install --force' kept hitting the stale cache entry and silently installed the old artifact. Cache entries are now '<pkg>-<version>-<sha8>.<ext>' (version and short artifact sha256 come straight from the index), so entries can never be reused across versions. The existing cache-hit path still requires the cached file to hash to the index artifacts[].sha256 and falls back to a fresh download otherwise, so same-version reinstalls keep reusing the cache while corrupted or polluted entries are discarded. Tests: cache key distinguishes versions (stale 1.0.0 entry cannot satisfy a 2.0.0 index), cached artifact with mismatched sha256 is re-downloaded, same version+sha still hits the cache, and a --force install after an index version bump installs the new artifact.
caomengxuan666
added a commit
that referenced
this pull request
Oct 10, 2026
…ing (#1158) in download_artifact
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.
Summary
wpm的下载缓存键此前只含包名(<pkg>.<ext>,src/commands/wpm.cppdownload_artifact)。索引 revision 升级包版本(新 URL + 新 sha256)后,wpm install --force仍命中旧缓存条目并静默安装旧产物——正是 #1154 实测复现的静默错误。修复:缓存文件名改为
<pkg>-<version>-<sha8>.<ext>,版本与短产物哈希直接取自 index.json(packages[].version/artifacts[].sha256),结构上杜绝跨版本复用:artifact_cache_filename()+sanitize_cache_key_component()(版本/包名中的文件系统不安全字符替换为_);download_artifact()增加 version 参数,install与wpm update(自更新)两个调用点传入;artifacts[].sha256(cached_artifact_is_valid),不符即删除缓存重新下载——同版本--force重装继续复用缓存,缓存损坏/污染自动重下;wpm clean cache可一次性清除(行为已有,无需迁移)。不新增任何用户可见文案(无需 i18n 同步)。
关联 issue
closes #1154
实测复现引用(2026-10-10,wpm 0.4.0,WinuxCmd 1.3.3 自带,#1154 原文):
wpm install niugit --force—— 输出extracting niugit.zip+installed niugit(报成功);opt/niugit/git.exe仍是旧版(sha256 前缀E5BFBF9C,v2.55.0.2 产物);.wpm/cache/niugit.zip哈希FC293AD2...为旧 zip,缓存键只含包名;wpm clean cache后重装才装上 2.55.0.3(6FC85A25...)。期间--force五次重装全部报成功但文件未变。Test plan
scripts/build-with-vs.ps1(VS18 / Ninja / Debug,-DBUILD_FFI=OFF)构建通过winuxcmd-tests --gtest_filter=wpm.*:44/44 通过,含 3 个新增回归测试 + 1 个更新测试:wpm_install_cache_key_distinguishes_versions:旧版本缓存条目(含旧格式<pkg>.<ext>)无法满足新版本索引(该用例在修复前必失败——旧键 + sha 匹配即命中)wpm_install_redownloads_when_cached_artifact_sha_mismatches:缓存键正确但内容损坏 → 重新下载并替换缓存wpm_install_force_after_version_bump_installs_new_artifact:索引升版后--force重装落盘新产物,生成新缓存条目wpm_install_uses_valid_cached_artifact_before_downloading:同版本+同 sha 命中新格式缓存,不下载grep.grep_l_exit_zero_iff_any_line_selected与grep.grep_r_skips_cross_junction_trees_without_crashing(junction 相关环境性失败,与本 diff 无关——本 PR 仅改src/commands/wpm.cpp与 wpm 单测)scripts/format.py(clang-format)已运行,仅保留本任务两个文件的改动