Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/uv-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ uv-settings = { workspace = true }
uv-state = { workspace = true }
uv-static = { workspace = true }
uv-virtualenv = { workspace = true }

fs-err = { workspace = true }
pathdiff = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }
toml = { workspace = true }
toml_edit = { workspace = true }
tracing = { workspace = true }

[target.'cfg(target_os = "windows")'.dependencies]
self-replace = { workspace = true }
12 changes: 10 additions & 2 deletions crates/uv-tool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,16 @@ impl InstalledTools {
environment_path.user_display()
);

// TODO(charlie): On Windows, if the current executable is in the directory,
// we need to use `safe_delete`.
// On Windows, if the current executable is in the directory, guard against self-deletion.
#[cfg(windows)]
if let Ok(itself) = std::env::current_exe() {
let target = std::path::absolute(&environment_path)?;
if itself.starts_with(&target) {
debug!("Detected self-delete of executable: {}", itself.display());
self_replace::self_delete_outside_path(&environment_path)?;
}
}

fs_err::remove_dir_all(environment_path)?;

Ok(())
Expand Down
3 changes: 3 additions & 0 deletions crates/uv-virtualenv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ itertools = { workspace = true }
pathdiff = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }

[target.'cfg(target_os = "windows")'.dependencies]
self-replace = { workspace = true }
14 changes: 12 additions & 2 deletions crates/uv-virtualenv/src/virtualenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,19 @@ pub(crate) fn create(
if allow_existing {
debug!("Allowing existing directory");
} else if location.join("pyvenv.cfg").is_file() {
// TODO(charlie): On Windows, if the current executable is in the directory,
// we need to use `safe_delete`.
debug!("Removing existing directory");

// On Windows, if the current executable is in the directory, guard against
// self-deletion.
#[cfg(windows)]
if let Ok(itself) = std::env::current_exe() {
let target = std::path::absolute(location)?;
if itself.starts_with(&target) {
debug!("Detected self-delete of executable: {}", itself.display());
self_replace::self_delete_outside_path(location)?;
}
}

fs::remove_dir_all(location)?;
fs::create_dir_all(location)?;
} else if location
Expand Down