Skip to content

Commit e52fd1a

Browse files
committed
fix(command-vendor): reproduce the panic of cp_sources
1 parent 28163c0 commit e52fd1a

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/cargo/ops/vendor.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ fn sync(
233233
&format!("{} ({}) to {}", id, src.to_string_lossy(), dst.display()),
234234
)?;
235235

236-
let _ = fs::remove_dir_all(&dst);
236+
// Comment it to keep the blocking file to force rename failure.
237+
// This action Will be undo later.
238+
// let _ = fs::remove_dir_all(&dst);
237239

238240
let mut file_cksums = BTreeMap::new();
239241

tests/testsuite/vendor.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,3 +2086,44 @@ Caused by:
20862086
"#]])
20872087
.run();
20882088
}
2089+
2090+
#[cargo_test]
2091+
fn vendor_rename_fallback() {
2092+
let p = project()
2093+
.file(
2094+
"Cargo.toml",
2095+
r#"
2096+
[package]
2097+
name = "foo"
2098+
version = "0.1.0"
2099+
2100+
[dependencies]
2101+
log = "0.3.5"
2102+
"#,
2103+
)
2104+
.file("src/lib.rs", "")
2105+
.build();
2106+
2107+
Package::new("log", "0.3.5").publish();
2108+
2109+
// Create vendor/log/blocking_file as a file to force rename failure
2110+
let log_pkg_dir= p.root().join("vendor").join("log");
2111+
let block_file_path = log_pkg_dir.join("blocking_file");
2112+
fs::create_dir_all(&log_pkg_dir).unwrap();
2113+
fs::write(block_file_path, "blocking file").unwrap();
2114+
2115+
p.cargo("vendor --respect-source-config --no-delete")
2116+
.env("CARGO_LOG", "cargo::ops::vendor=warn")
2117+
.with_status(101)
2118+
.with_stderr_data(str![[r#"
2119+
...
2120+
[..]failed to `mv "[..]vendor[..].vendor-staging[..]log-0.3.5" "[..]vendor[..]log"`: [..]
2121+
...
2122+
[..]StripPrefixError[..]
2123+
...
2124+
"#]])
2125+
.run();
2126+
2127+
// Assert cp_sources fallback didn't work
2128+
assert!(!p.root().join("vendor/log/Cargo.toml").exists());
2129+
}

0 commit comments

Comments
 (0)