Skip to content
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
14 changes: 13 additions & 1 deletion crates/uv-dirs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use uv_static::EnvVars;
pub fn user_executable_directory(override_variable: Option<&'static str>) -> Option<PathBuf> {
override_variable
.and_then(std::env::var_os)
.and_then(parse_xdg_path)
.and_then(parse_path)
.or_else(|| std::env::var_os(EnvVars::XDG_BIN_HOME).and_then(parse_xdg_path))
.or_else(|| {
std::env::var_os(EnvVars::XDG_DATA_HOME)
Expand Down Expand Up @@ -83,6 +83,18 @@ pub fn legacy_user_state_dir() -> Option<PathBuf> {
.map(|dir| if cfg!(windows) { dir.join("data") } else { dir })
}

/// Return a [`PathBuf`] from the given [`OsString`], if non-empty.
///
/// Unlike [`parse_xdg_path`], this function accepts both relative and absolute paths,
/// for use with uv-specific override variables that are not subject to the XDG specification.
fn parse_path(path: OsString) -> Option<PathBuf> {
if path.is_empty() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why special-case an empty string? Couldn't that usefully mean "the cwd itself"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's for consistency with the rest of our variables. People want to the ability to "unset" a variable using an empty value. I think you should use . to target the CWD.

None
} else {
Some(PathBuf::from(path))
}
}

/// Return a [`PathBuf`] if the given [`OsString`] is an absolute path.
///
/// Relative paths are considered invalid per the [XDG Base Directory Specification]:
Expand Down
Loading