From 17181fef07326707ca6921aba28d1dbdd1e6ce83 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Thu, 23 Oct 2025 15:08:53 -0500 Subject: [PATCH] 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. --- crates/uv-virtualenv/src/virtualenv.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/uv-virtualenv/src/virtualenv.rs b/crates/uv-virtualenv/src/virtualenv.rs index c564d0692..04b4c1016 100644 --- a/crates/uv-virtualenv/src/virtualenv.rs +++ b/crates/uv-virtualenv/src/virtualenv.rs @@ -628,7 +628,21 @@ pub fn remove_virtualenv(location: &Path) -> Result<(), Error> { Err(err) if err.kind() == io::ErrorKind::NotFound => {} 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(()) }