Skip to content

Commit

Permalink
Include explicit separator when constructing path to Windows global c…
Browse files Browse the repository at this point in the history
…onfig file
  • Loading branch information
zanieb committed Nov 25, 2024
1 parent 21aa9bc commit 2b96093
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions crates/uv-settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,25 @@ fn locate_system_config_xdg(value: Option<&str>) -> Option<PathBuf> {
None
}

#[cfg(windows)]
fn locate_system_config_windows(system_drive: &std::ffi::OsStr) -> 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 = PathBuf::from(system_drive);

// `PathBuf::join` does not include a separator for system drives, so we need to include it
// manually. However, we allow arbitrary file paths in the `SYSTEMDRIVE` environment variable
// for testing so we check if the path is actually a drive before adding the separator.
//
// See https://github.com/rust-lang/rust/blob/7db7489f9bc274cb60c4956bfa56de0185eb1b9b/library/std/src/path.rs#L1305-L1313
let components = candidate.components();
let prefix = if comps.prefix_len() > 0
&& comps.prefix_len() == comps.path.len()
&& comps.prefix.unwrap().is_drive() {
"\\"
} else {
""
};

let candidate = candidate.join(format!("{prefix}ProgramData\\uv\\uv.toml"));
candidate.as_path().is_file().then_some(candidate)
}

Expand Down

0 comments on commit 2b96093

Please sign in to comment.