Skip to content

Commit f381571

Browse files
committed
Add tracker verification for test case uninstall_running_binary
1 parent 1e3b423 commit f381571

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

src/cargo/ops/cargo_uninstall.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,18 @@ fn uninstall_pkgid(
135135
}
136136
}
137137

138-
let to_remove: Vec<&String> = {
138+
let to_remove = {
139139
if bins.is_empty() {
140-
installed.iter().collect()
140+
installed
141141
} else {
142-
bins.iter().collect()
142+
bins
143143
}
144144
};
145145

146146
for bin in to_remove {
147-
let bin_path = dst.join(bin);
147+
let bin_path = dst.join(&bin);
148148
config.shell().status("Removing", bin_path.display())?;
149-
tracker.remove_bin_then_save(pkgid, bin, &bin_path)?;
149+
tracker.remove_bin_then_save(pkgid, &bin, &bin_path)?;
150150
}
151151

152152
Ok(())

src/cargo/ops/common_for_install_and_uninstall.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ impl InstallTracker {
321321
self.v2.remove(pkg_id, bins);
322322
}
323323

324-
/// Remove a bin after it successfully had been removed in disk and the save the tracker at last.
324+
/// Remove a bin after it successfully had been removed in disk and then save the tracker at last.
325325
pub fn remove_bin_then_save(
326326
&mut self,
327327
pkg_id: PackageId,

tests/testsuite/install.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,6 +2508,36 @@ fn install_incompat_msrv() {
25082508
.with_status(101).run();
25092509
}
25102510

2511+
fn v1_path() -> PathBuf {
2512+
cargo_home().join(".crates.toml")
2513+
}
2514+
2515+
fn v2_path() -> PathBuf {
2516+
cargo_home().join(".crates2.json")
2517+
}
2518+
2519+
fn load_crates1() -> toml::Value {
2520+
toml::from_str(&fs::read_to_string(v1_path()).unwrap()).unwrap()
2521+
}
2522+
2523+
fn load_crates2() -> serde_json::Value {
2524+
serde_json::from_str(&fs::read_to_string(v2_path()).unwrap()).unwrap()
2525+
}
2526+
2527+
fn assert_tracker_noexistence(key: &str) {
2528+
let data = load_crates1();
2529+
assert!(data["v1"].get(key).is_none());
2530+
let data = load_crates2();
2531+
assert!(data["installs"][key].is_null());
2532+
}
2533+
2534+
fn assert_tracker_existence(key: &str) {
2535+
let data = load_crates1();
2536+
assert!(!data["v1"].get(key).is_none());
2537+
let data = load_crates2();
2538+
assert!(!data["installs"][key].is_null());
2539+
}
2540+
25112541
#[cfg(windows)]
25122542
#[cargo_test]
25132543
fn uninstall_running_binary() {
@@ -2568,9 +2598,15 @@ fn uninstall_running_binary() {
25682598
assert_has_installed_exe(cargo_home(), "foo");
25692599

25702600
t.join().unwrap();
2601+
2602+
let key = "foo 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)";
2603+
assert_tracker_existence(key);
25712604
cargo_process("uninstall foo")
25722605
.with_stderr("[REMOVING] [CWD]/home/.cargo/bin/foo[EXE]")
25732606
.run();
2607+
assert_has_not_installed_exe(cargo_home(), "foo");
2608+
assert_tracker_noexistence(key);
2609+
25742610
cargo_process("install foo")
25752611
.with_stderr(
25762612
"\

0 commit comments

Comments
 (0)