Skip to content

Commit 87110b2

Browse files
committed
Avoid removing empty directories when constructing virtual environments
1 parent 7887285 commit 87110b2

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

crates/uv-virtualenv/src/virtualenv.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use fs_err as fs;
1010
use fs_err::File;
1111
use itertools::Itertools;
1212
use owo_colors::OwoColorize;
13-
use tracing::debug;
13+
use tracing::{debug, trace};
1414

1515
use uv_configuration::PreviewMode;
1616
use uv_fs::{CWD, Simplified, cachedir};
@@ -85,6 +85,18 @@ pub(crate) fn create(
8585
format!("File exists at `{}`", location.user_display()),
8686
)));
8787
}
88+
Ok(metadata)
89+
if metadata.is_dir()
90+
&& location
91+
.read_dir()
92+
.is_ok_and(|mut dir| dir.next().is_none()) =>
93+
{
94+
// If it's an empty directory, we can proceed
95+
trace!(
96+
"Using empty directory at `{}` for virtual environment",
97+
location.user_display()
98+
);
99+
}
88100
Ok(metadata) if metadata.is_dir() => {
89101
let name = if uv_fs::is_virtualenv_base(location) {
90102
"virtual environment"
@@ -100,13 +112,6 @@ pub(crate) fn create(
100112
remove_virtualenv(location)?;
101113
fs::create_dir_all(location)?;
102114
}
103-
OnExisting::Fail
104-
if location
105-
.read_dir()
106-
.is_ok_and(|mut dir| dir.next().is_none()) =>
107-
{
108-
debug!("Ignoring empty directory");
109-
}
110115
OnExisting::Fail => {
111116
match confirm_clear(location, name)? {
112117
Some(true) => {

0 commit comments

Comments
 (0)