Avoid crash for XDG_CONFIG_HOME=/dev/null (#4200)

## Summary

Closes https://github.com/astral-sh/uv/issues/4199.

## Test Plan

`XDG_CONFIG_HOME=/dev/null cargo run venv`
This commit is contained in:
Charlie Marsh
2024-06-10 10:36:29 -07:00
committed by GitHub
parent fc4c2be3aa
commit 652c1126d3
+8
View File
@@ -27,6 +27,14 @@ impl Workspace {
match read_file(&file) {
Ok(options) => Ok(Some(Self { options, root })),
Err(WorkspaceError::Io(err)) if err.kind() == std::io::ErrorKind::NotFound => Ok(None),
Err(_) if !dir.is_dir() => {
// Ex) `XDG_CONFIG_HOME=/dev/null`
debug!(
"User configuration directory `{}` does not exist or is not a directory",
dir.display()
);
Ok(None)
}
Err(err) => Err(err),
}
}