mirror of https://github.com/astral-sh/uv
Guard against self-deletion in `uv venv` and `uv tool` (#10206)
## Summary Closes https://github.com/astral-sh/uv/issues/1327.
This commit is contained in:
parent
4b5a89dbff
commit
cecff3a726
|
|
@ -5558,6 +5558,7 @@ version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fs-err 3.0.0",
|
"fs-err 3.0.0",
|
||||||
"pathdiff",
|
"pathdiff",
|
||||||
|
"self-replace",
|
||||||
"serde",
|
"serde",
|
||||||
"thiserror 2.0.9",
|
"thiserror 2.0.9",
|
||||||
"toml",
|
"toml",
|
||||||
|
|
@ -5624,6 +5625,7 @@ dependencies = [
|
||||||
"fs-err 3.0.0",
|
"fs-err 3.0.0",
|
||||||
"itertools 0.13.0",
|
"itertools 0.13.0",
|
||||||
"pathdiff",
|
"pathdiff",
|
||||||
|
"self-replace",
|
||||||
"thiserror 2.0.9",
|
"thiserror 2.0.9",
|
||||||
"tracing",
|
"tracing",
|
||||||
"uv-fs",
|
"uv-fs",
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ uv-settings = { workspace = true }
|
||||||
uv-state = { workspace = true }
|
uv-state = { workspace = true }
|
||||||
uv-static = { workspace = true }
|
uv-static = { workspace = true }
|
||||||
uv-virtualenv = { workspace = true }
|
uv-virtualenv = { workspace = true }
|
||||||
|
|
||||||
fs-err = { workspace = true }
|
fs-err = { workspace = true }
|
||||||
pathdiff = { workspace = true }
|
pathdiff = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
|
|
@ -36,3 +37,6 @@ thiserror = { workspace = true }
|
||||||
toml = { workspace = true }
|
toml = { workspace = true }
|
||||||
toml_edit = { workspace = true }
|
toml_edit = { workspace = true }
|
||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
|
self-replace = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -184,8 +184,16 @@ impl InstalledTools {
|
||||||
environment_path.user_display()
|
environment_path.user_display()
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO(charlie): On Windows, if the current executable is in the directory,
|
// On Windows, if the current executable is in the directory, guard against self-deletion.
|
||||||
// we need to use `safe_delete`.
|
#[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)?;
|
fs_err::remove_dir_all(environment_path)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -32,3 +32,6 @@ itertools = { workspace = true }
|
||||||
pathdiff = { workspace = true }
|
pathdiff = { workspace = true }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
|
self-replace = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -105,9 +105,19 @@ pub(crate) fn create(
|
||||||
if allow_existing {
|
if allow_existing {
|
||||||
debug!("Allowing existing directory");
|
debug!("Allowing existing directory");
|
||||||
} else if location.join("pyvenv.cfg").is_file() {
|
} 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");
|
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::remove_dir_all(location)?;
|
||||||
fs::create_dir_all(location)?;
|
fs::create_dir_all(location)?;
|
||||||
} else if location
|
} else if location
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue