mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-30 23:37:24 +00:00
uv python install
: remove the existing version only after the new installation is downloaded successfully (#8485)
## Summary This PR delays the removal of an existing version after downloading the new version when running `uv python install --reinstall`. If the download fails, we can keep the existing version working. ## Test Plan ```console $ cargo run -- python install 3.13 $ cargo run -- python install --reinstall 3.13 # when downloading, `ctrl-c` to interrupt $ cargo run -- python list ```
This commit is contained in:
parent
9ca1f0003f
commit
56f93d9cfc
3 changed files with 18 additions and 7 deletions
|
@ -465,13 +465,14 @@ impl ManagedPythonDownload {
|
|||
client: &uv_client::BaseClient,
|
||||
installation_dir: &Path,
|
||||
cache_dir: &Path,
|
||||
reinstall: bool,
|
||||
reporter: Option<&dyn Reporter>,
|
||||
) -> Result<DownloadResult, Error> {
|
||||
let url = self.download_url()?;
|
||||
let path = installation_dir.join(self.key().to_string());
|
||||
|
||||
// If it already exists, return it
|
||||
if path.is_dir() {
|
||||
// If it is not a reinstall and the dir already exists, return it.
|
||||
if !reinstall && path.is_dir() {
|
||||
return Ok(DownloadResult::AlreadyAvailable(path));
|
||||
}
|
||||
|
||||
|
@ -560,7 +561,13 @@ impl ManagedPythonDownload {
|
|||
}
|
||||
}
|
||||
|
||||
// Persist it to the target
|
||||
// Remove the target if it already exists.
|
||||
if path.is_dir() {
|
||||
debug!("Removing existing directory: {}", path.user_display());
|
||||
fs_err::tokio::remove_dir_all(&path).await?;
|
||||
}
|
||||
|
||||
// Persist it to the target.
|
||||
debug!("Moving {} to {}", extracted.display(), path.user_display());
|
||||
rename_with_retry(extracted, &path)
|
||||
.await
|
||||
|
|
|
@ -132,7 +132,7 @@ impl PythonInstallation {
|
|||
|
||||
info!("Fetching requested Python...");
|
||||
let result = download
|
||||
.fetch(&client, installations_dir, &cache_dir, reporter)
|
||||
.fetch(&client, installations_dir, &cache_dir, false, reporter)
|
||||
.await?;
|
||||
|
||||
let path = match result {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue