Skip to content

Commit 22f0d39

Browse files
committed
fix(command-vendor): fix the issue
1 parent 2f83c73 commit 22f0d39

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/cargo/ops/vendor.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,23 @@ fn sync(
292292
let unpacked_src =
293293
registry.unpack_package_in(id, staging_dir.path(), &vendor_this)?;
294294
if let Err(e) = fs::rename(&unpacked_src, &dst) {
295-
// This fallback is mainly for Windows 10 versions earlier than 1607.
296-
// The destination of `fs::rename` can't be a directory in older versions.
297-
// Can be removed once the minimal supported Windows version gets bumped.
295+
// This fallback is worked for sometimes `fs::rename` failed in a specific situation, such as:
296+
// - In Windows 10 versions earlier than 1607, the destination of `fs::rename` can't be a directory in older versions.
297+
// - `from` and `to` are on separate filesystems.
298+
// - AntiVirus or our system indexer are doing stuf simutaneously.
299+
// - Any other reasons documented in std::fs::rename.
298300
tracing::warn!("failed to `mv {unpacked_src:?} {dst:?}`: {e}");
299301
let paths: Vec<_> = walkdir(&unpacked_src).map(|e| e.into_path()).collect();
300-
cp_sources(pkg, src, &paths, &dst, &mut file_cksums, &mut tmp_buf, gctx)
301-
.with_context(|| format!("failed to copy vendored sources for {id}"))?;
302+
cp_sources(
303+
pkg,
304+
&unpacked_src,
305+
&paths,
306+
&dst,
307+
&mut file_cksums,
308+
&mut tmp_buf,
309+
gctx,
310+
)
311+
.with_context(|| format!("failed to copy vendored sources for {id}"))?;
302312
} else {
303313
compute_file_cksums(&dst)?;
304314
}

tests/testsuite/vendor.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,11 +2118,18 @@ fn vendor_rename_fallback() {
21182118
...
21192119
[..]failed to `mv "[..]vendor[..].vendor-staging[..]log-0.3.5" "[..]vendor[..]log"`: [..]
21202120
...
2121-
[..]StripPrefixError[..]
2121+
Caused by:
2122+
failed to copy vendored sources for log v0.3.5
2123+
2124+
Caused by:
2125+
failed to create directory `[..]log`
2126+
2127+
Caused by:
2128+
File exists[..]
21222129
...
21232130
"#]])
21242131
.run();
21252132

2126-
// The cp_sources fallback didn't work because of the StripPrefixError
2133+
// The cp_sources fallback didn't work because the vendor/log file still exists, not becuase of StripPrefixError
21272134
assert!(!p.root().join("vendor/log/Cargo.toml").exists());
21282135
}

0 commit comments

Comments
 (0)