Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert backslash when appending to system drive #9488

Merged
merged 2 commits into from
Nov 28, 2024
Merged
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
20 changes: 11 additions & 9 deletions crates/uv-settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,13 @@ fn locate_system_config_xdg(value: Option<&str>) -> Option<PathBuf> {
}

#[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`).
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)
}

Expand All @@ -217,8 +221,9 @@ fn locate_system_config_windows(system_drive: &std::ffi::OsStr) -> Option<PathBu
fn system_config_file() -> Option<PathBuf> {
#[cfg(windows)]
{
env::var_os(EnvVars::SYSTEMDRIVE)
.and_then(|system_drive| locate_system_config_windows(&system_drive))
env::var(EnvVars::SYSTEMDRIVE)
.ok()
.and_then(|system_drive| locate_system_config_windows(format!("{system_drive}\\")))
}

#[cfg(not(windows))]
Expand Down Expand Up @@ -369,7 +374,7 @@ mod test {
// This is typically only a drive (that is, letter and colon) but we
// allow anything, including a path to the test fixtures...
assert_eq!(
locate_system_config_windows(context.path().as_os_str()).unwrap(),
locate_system_config_windows(context.path()).unwrap(),
context
.child("ProgramData")
.child("uv")
Expand All @@ -379,10 +384,7 @@ mod test {

// This does not have a `ProgramData` child, so contains no config.
let context = assert_fs::TempDir::new()?;
assert_eq!(
locate_system_config_windows(context.path().as_os_str()),
None
);
assert_eq!(locate_system_config_windows(context.path()), None);

Ok(())
}
Expand Down
Loading