mirror of
https://github.com/astral-sh/uv.git
synced 2025-09-23 02:32:33 +00:00
Insert backslash when appending to system drive (#9488)
## Summary When you pass a system drive to `Path::join`, Rust doesn't insert a backslash between the drive and the path itself, so our lookups for system configuration were failing. Closes https://github.com/astral-sh/uv/issues/9416.
This commit is contained in:
parent
aa688226aa
commit
201dfef780
1 changed files with 11 additions and 9 deletions
|
@ -202,9 +202,13 @@ fn locate_system_config_xdg(value: Option<&str>) -> Option<PathBuf> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn locate_system_config_windows(system_drive: &std::ffi::OsStr) -> Option<PathBuf> {
|
fn locate_system_config_windows(system_drive: impl AsRef<Path>) -> Option<PathBuf> {
|
||||||
// On Windows, use `%SYSTEMDRIVE%\ProgramData\uv\uv.toml` (e.g., `C:\ProgramData`).
|
// On Windows, use `%SYSTEMDRIVE%\ProgramData\uv\uv.toml` (e.g., `C:\ProgramData`).
|
||||||
let candidate = PathBuf::from(system_drive).join("ProgramData\\uv\\uv.toml");
|
let candidate = system_drive
|
||||||
|
.as_ref()
|
||||||
|
.join("ProgramData")
|
||||||
|
.join("uv")
|
||||||
|
.join("uv.toml");
|
||||||
candidate.as_path().is_file().then_some(candidate)
|
candidate.as_path().is_file().then_some(candidate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,8 +221,9 @@ fn locate_system_config_windows(system_drive: &std::ffi::OsStr) -> Option<PathBu
|
||||||
fn system_config_file() -> Option<PathBuf> {
|
fn system_config_file() -> Option<PathBuf> {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
env::var_os(EnvVars::SYSTEMDRIVE)
|
env::var(EnvVars::SYSTEMDRIVE)
|
||||||
.and_then(|system_drive| locate_system_config_windows(&system_drive))
|
.ok()
|
||||||
|
.and_then(|system_drive| locate_system_config_windows(format!("{system_drive}\\")))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
|
@ -369,7 +374,7 @@ mod test {
|
||||||
// This is typically only a drive (that is, letter and colon) but we
|
// This is typically only a drive (that is, letter and colon) but we
|
||||||
// allow anything, including a path to the test fixtures...
|
// allow anything, including a path to the test fixtures...
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
locate_system_config_windows(context.path().as_os_str()).unwrap(),
|
locate_system_config_windows(context.path()).unwrap(),
|
||||||
context
|
context
|
||||||
.child("ProgramData")
|
.child("ProgramData")
|
||||||
.child("uv")
|
.child("uv")
|
||||||
|
@ -379,10 +384,7 @@ mod test {
|
||||||
|
|
||||||
// This does not have a `ProgramData` child, so contains no config.
|
// This does not have a `ProgramData` child, so contains no config.
|
||||||
let context = assert_fs::TempDir::new()?;
|
let context = assert_fs::TempDir::new()?;
|
||||||
assert_eq!(
|
assert_eq!(locate_system_config_windows(context.path()), None);
|
||||||
locate_system_config_windows(context.path().as_os_str()),
|
|
||||||
None
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue