diff --git a/e2e/cli/test_uninstall b/e2e/cli/test_uninstall index 3717cadbc86..702ca090780 100644 --- a/e2e/cli/test_uninstall +++ b/e2e/cli/test_uninstall @@ -30,3 +30,15 @@ assert_contains "mise ls --installed dummy" "1.0.0" # Test: --dry-run-code should exit 0 when the tool is not installed mise uninstall dummy@1.0.0 assert_succeed "mise uninstall dummy@1.0.0 --dry-run-code 2>&1" + +# Test: a dry run reports each version once, naming every path it would remove +mise i dummy@1.0.0 dummy@1.1.0 +mkdir -p "$(mise cache path 2>/dev/null || echo "$MISE_CACHE_DIR")/dummy/1.0.0" "$(mise cache path 2>/dev/null || echo "$MISE_CACHE_DIR")/dummy/1.1.0" +out="$(mise uninstall --all --dry-run dummy 2>&1)" +for v in 1.0.0 1.1.0; do + assert_contains_text "count=$(grep -c "dummy@$v .*remove" <<<"$out")" "count=1" + row="$(grep "dummy@$v .*remove" <<<"$out")" + assert_contains_text "$row" "installs/dummy/$v" + # the install path and the cache path + assert_contains_text "paths=$(grep -o "dummy/$v" <<<"$row" | wc -l | tr -d ' ')" "paths=2" +done diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 7d9f7a86779..47f83d15c37 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -4468,12 +4468,15 @@ pub trait Backend: Debug + Send + Sync { if !dryrun { self.uninstall_version_impl(config, pr, tv).await?; } - let rmdir = |dir: &Path| { + // A dry run reports once, after every path is known: each message on a live + // progress row is drawn as a row of its own, so reporting per path repeated the row. + let mut would_remove: Vec = vec![]; + let mut rmdir = |dir: &Path| { if dryrun { // Not `exists()`, which resolves a link: a dry run has to name the entry the real // run would remove, and a link whose target is gone is one of them. if entry_exists(dir) { - pr.set_message(format!("remove {}", display_path(dir))); + would_remove.push(display_path(dir)); } return Ok(()); } @@ -4494,7 +4497,11 @@ pub trait Backend: Debug + Send + Sync { rmdir(&tv.download_path())?; } rmdir(&tv.cache_path())?; - if !dryrun { + if dryrun { + if !would_remove.is_empty() { + pr.set_message(format!("remove {}", would_remove.join(", "))); + } + } else { self.cleanup_empty_installs_dir(); } Ok(()) diff --git a/src/cli/uninstall.rs b/src/cli/uninstall.rs index 266e4640130..6fc91ff11d6 100644 --- a/src/cli/uninstall.rs +++ b/src/cli/uninstall.rs @@ -134,6 +134,14 @@ impl Uninstall { warn!("{} is not installed", tv.style()); continue; } + // `--all` lists what is installed, but a configured request (`27`) can stand + // for an installation under another name (`temurin-27.0.0+35`) and so name + // a directory that does not exist. Only stale cache under that name would be + // reported, as if a second installation were being removed. + if self.all && !file::entry_exists(tv.install_path()) { + debug!("{} has no installation to remove", tv.style()); + continue; + } to_remove.push((plugin, tv)); } let has_work = !to_remove.is_empty();