@@ -38,6 +38,30 @@ vendor_root="lib/vendor"
3838history_root=" lib/vendor-history"
3939manifest_root=" lib/vendor-manifest"
4040
41+ find_cached_src_dir () {
42+ find " $HOME /.cargo/registry/src" -maxdepth 2 -type d -name " ${crate} -${version} " 2> /dev/null \
43+ | head -n 1
44+ }
45+
46+ fetch_into_cache () {
47+ local fetch_tmp
48+ fetch_tmp=" $( mktemp -d) "
49+ cat > " ${fetch_tmp} /Cargo.toml" << EOF
50+ [package]
51+ name = "vendor-fetch-${crate} "
52+ version = "0.0.0"
53+ edition = "2021"
54+
55+ [dependencies]
56+ ${crate} = "= ${version} "
57+ EOF
58+ mkdir -p " ${fetch_tmp} /src"
59+ printf ' %s\n' ' fn main() {}' > " ${fetch_tmp} /src/main.rs"
60+
61+ cargo fetch --manifest-path " ${fetch_tmp} /Cargo.toml" > /dev/null 2>&1 || true
62+ rm -rf " $fetch_tmp "
63+ }
64+
4165resolve_version_from_lock () {
4266 awk -v crate=" $crate " '
4367 BEGIN { name = ""; version = ""; source = "" }
@@ -93,15 +117,16 @@ if [[ -z "$version" ]]; then
93117 exit 1
94118fi
95119
96- src_dir=" $( {
97- find " $HOME /.cargo/registry/src" -maxdepth 2 -type d -name " ${crate} -${version} " 2> /dev/null \
98- | head -n 1
99- } || true) "
120+ src_dir=" $( find_cached_src_dir || true) "
100121
101122if [[ -z " $src_dir " ]]; then
102- echo " error: could not find ${crate} -${version} in cargo cache"
103- echo " hint: run 'cargo fetch -p ${crate} @${version} ' in a clean Cargo state and retry"
104- exit 1
123+ fetch_into_cache
124+ src_dir=" $( find_cached_src_dir || true) "
125+ if [[ -z " $src_dir " ]]; then
126+ echo " error: could not find ${crate} -${version} in cargo cache after auto-fetch"
127+ echo " hint: check network/cargo registry config, then retry"
128+ exit 1
129+ fi
105130fi
106131
107132mkdir -p " $history_root " " $vendor_root " " $manifest_root "
0 commit comments