Avoid creating cache directories in tool directory (#4868)

Closes https://github.com/astral-sh/uv/issues/4867.
This commit is contained in:
Charlie Marsh 2024-07-07 16:19:07 -05:00 committed by GitHub
parent a302d704c5
commit 389582a37e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 10 deletions

View file

@ -11,7 +11,11 @@ use crate::commands::ExitStatus;
use crate::printer::Printer;
/// List installed tools.
pub(crate) async fn list(preview: PreviewMode, printer: Printer) -> Result<ExitStatus> {
pub(crate) async fn list(
preview: PreviewMode,
cache: &Cache,
printer: Printer,
) -> Result<ExitStatus> {
if preview.is_disabled() {
warn_user_once!("`uv tool list` is experimental and may change without warning.");
}
@ -28,14 +32,13 @@ pub(crate) async fn list(preview: PreviewMode, printer: Printer) -> Result<ExitS
for (name, tool) in tools {
// Output tool name and version
let version =
match installed_tools.version(&name, &Cache::from_path(installed_tools.root())) {
Ok(version) => version,
Err(e) => {
writeln!(printer.stderr(), "{e}")?;
continue;
}
};
let version = match installed_tools.version(&name, cache) {
Ok(version) => version,
Err(e) => {
writeln!(printer.stderr(), "{e}")?;
continue;
}
};
writeln!(printer.stdout(), "{name} v{version}")?;

View file

@ -715,7 +715,10 @@ async fn run() -> Result<ExitStatus> {
let args = settings::ToolListSettings::resolve(args, filesystem);
show_settings!(args);
commands::tool_list(globals.preview, printer).await
// Initialize the cache.
let cache = cache.init()?;
commands::tool_list(globals.preview, &cache, printer).await
}
Commands::Tool(ToolNamespace {
command: ToolCommand::Uninstall(args),