mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 05:15:00 +00:00
Remove dangling environments in tool uninstall
(#4740)
## Summary It seems useful that `tool uninstall` guarantees the tool is gone (e.g., if the receipt and environment get out-of-sync somehow).
This commit is contained in:
parent
32dc9bef59
commit
676d550410
2 changed files with 19 additions and 4 deletions
|
@ -25,7 +25,22 @@ pub(crate) async fn uninstall(
|
|||
|
||||
let installed_tools = InstalledTools::from_settings()?;
|
||||
let Some(receipt) = installed_tools.get_tool_receipt(&name)? else {
|
||||
bail!("Tool `{}` is not installed", name);
|
||||
// If the tool is not installed, attempt to remove the environment anyway.
|
||||
match installed_tools.remove_environment(&name) {
|
||||
Ok(()) => {
|
||||
writeln!(
|
||||
printer.stderr(),
|
||||
"Removed dangling environment for tool: `{name}` (missing receipt)"
|
||||
)?;
|
||||
return Ok(ExitStatus::Success);
|
||||
}
|
||||
Err(uv_tool::Error::IO(err)) if err.kind() == std::io::ErrorKind::NotFound => {
|
||||
bail!("Tool `{name}` is not installed");
|
||||
}
|
||||
Err(err) => {
|
||||
return Err(err.into());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Remove the tool itself.
|
||||
|
|
|
@ -108,12 +108,12 @@ fn tool_uninstall_missing_receipt() {
|
|||
uv_snapshot!(context.filters(), context.tool_uninstall().arg("black")
|
||||
.env("UV_TOOL_DIR", tool_dir.as_os_str())
|
||||
.env("XDG_BIN_HOME", bin_dir.as_os_str()), @r###"
|
||||
success: false
|
||||
exit_code: 2
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
warning: `uv tool uninstall` is experimental and may change without warning.
|
||||
error: Tool `black` is not installed
|
||||
Removed dangling environment for tool: `black` (missing receipt)
|
||||
"###);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue