mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-19 11:35:36 +00:00
Avoid removing empty directories when constructing virtual environments (#14822)
Closes https://github.com/astral-sh/uv/issues/14815
I tested this with the docker-compose reproduction. You can also see a
regression test change at
2ae4464b7e
This commit is contained in:
parent
f0151f3a18
commit
076677da20
2 changed files with 59 additions and 8 deletions
|
|
@ -10,7 +10,7 @@ use fs_err as fs;
|
|||
use fs_err::File;
|
||||
use itertools::Itertools;
|
||||
use owo_colors::OwoColorize;
|
||||
use tracing::debug;
|
||||
use tracing::{debug, trace};
|
||||
|
||||
use uv_configuration::PreviewMode;
|
||||
use uv_fs::{CWD, Simplified, cachedir};
|
||||
|
|
@ -85,6 +85,18 @@ pub(crate) fn create(
|
|||
format!("File exists at `{}`", location.user_display()),
|
||||
)));
|
||||
}
|
||||
Ok(metadata)
|
||||
if metadata.is_dir()
|
||||
&& location
|
||||
.read_dir()
|
||||
.is_ok_and(|mut dir| dir.next().is_none()) =>
|
||||
{
|
||||
// If it's an empty directory, we can proceed
|
||||
trace!(
|
||||
"Using empty directory at `{}` for virtual environment",
|
||||
location.user_display()
|
||||
);
|
||||
}
|
||||
Ok(metadata) if metadata.is_dir() => {
|
||||
let name = if uv_fs::is_virtualenv_base(location) {
|
||||
"virtual environment"
|
||||
|
|
@ -100,13 +112,6 @@ pub(crate) fn create(
|
|||
remove_virtualenv(location)?;
|
||||
fs::create_dir_all(location)?;
|
||||
}
|
||||
OnExisting::Fail
|
||||
if location
|
||||
.read_dir()
|
||||
.is_ok_and(|mut dir| dir.next().is_none()) =>
|
||||
{
|
||||
debug!("Ignoring empty directory");
|
||||
}
|
||||
OnExisting::Fail => {
|
||||
match confirm_clear(location, name)? {
|
||||
Some(true) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue