Skip to content

Commit 39300ea

Browse files
committed
fix(command-vendor): fix it
1 parent 2845375 commit 39300ea

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/cargo/ops/vendor.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,23 @@ fn sync(
305305
};
306306

307307
if let Err(e) = rename_result {
308-
// This fallback is mainly for Windows 10 versions earlier than 1607.
309-
// The destination of `fs::rename` can't be a directory in older versions.
310-
// Can be removed once the minimal supported Windows version gets bumped.
308+
// This fallback is worked for sometimes `fs::rename` failed in a specific situation, such as:
309+
// - In Windows 10 versions earlier than 1607, the destination of `fs::rename` can't be a directory in older versions.
310+
// - `from` and `to` are on separate filesystems.
311+
// - AntiVirus or our system indexer are doing stuf simutaneously.
312+
// - Any other reasons documented in std::fs::rename.
311313
tracing::warn!("failed to `mv {unpacked_src:?} {dst:?}`: {e}");
312314
let paths: Vec<_> = walkdir(&unpacked_src).map(|e| e.into_path()).collect();
313-
cp_sources(pkg, src, &paths, &dst, &mut file_cksums, &mut tmp_buf, gctx)
314-
.with_context(|| format!("failed to copy vendored sources for {id}"))?;
315+
cp_sources(
316+
pkg,
317+
&unpacked_src,
318+
&paths,
319+
&dst,
320+
&mut file_cksums,
321+
&mut tmp_buf,
322+
gctx,
323+
)
324+
.with_context(|| format!("failed to copy vendored sources for {id}"))?;
315325
} else {
316326
compute_file_cksums(&dst)?;
317327
}

tests/testsuite/vendor.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,15 +2109,13 @@ fn vendor_rename_fallback() {
21092109
p.cargo("vendor --respect-source-config --no-delete")
21102110
.env("CARGO_LOG", "cargo::ops::vendor=warn")
21112111
.env("__CARGO_TEST_VENDOR_FALLBACK_CP_SOURCES", "true")
2112-
.with_status(101)
2112+
.with_status(0)
21132113
.with_stderr_data(str![[r#"
21142114
...
21152115
[..]failed to `mv "[..]vendor[..].vendor-staging[..]log-0.3.5" "[..]vendor[..]log"`: simulated rename error for testing
21162116
...
2117-
[..]StripPrefixError[..]
2118-
...
21192117
"#]])
21202118
.run();
21212119

2122-
assert!(!p.root().join("vendor/log/Cargo.toml").exists());
2120+
assert!(p.root().join("vendor/log/Cargo.toml").exists());
21232121
}

0 commit comments

Comments
 (0)