Do not error when a virtual environment directory cannot be removed due to a busy error (#16394)

Closes https://github.com/astral-sh/uv/issues/16218

This occurs when using a mounted file system in Docker.

We're almost always removing a virtual environment to replace it, and
removing the parent directory isn't necessary for that.
This commit is contained in:
Zanie Blue 2025-10-23 15:08:53 -05:00 committed by GitHub
parent 491293362f
commit 17181fef07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 1 deletions

View File

@ -628,7 +628,21 @@ pub fn remove_virtualenv(location: &Path) -> Result<(), Error> {
Err(err) if err.kind() == io::ErrorKind::NotFound => {} Err(err) if err.kind() == io::ErrorKind::NotFound => {}
Err(err) => return Err(err.into()), Err(err) => return Err(err.into()),
} }
fs_err::remove_dir_all(location)?;
// Remove the virtual environment directory itself
match fs_err::remove_dir_all(location) {
Ok(()) => {}
Err(err) if err.kind() == io::ErrorKind::NotFound => {}
// If the virtual environment is a mounted file system, e.g., in a Docker container, we
// cannot delete it — but that doesn't need to be a fatal error
Err(err) if err.kind() == io::ErrorKind::ResourceBusy => {
debug!(
"Skipping removal of `{}` directory due to {err}",
location.display(),
);
}
Err(err) => return Err(err.into()),
}
Ok(()) Ok(())
} }