-
Notifications
You must be signed in to change notification settings - Fork 901
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
Eliminate dependencies on directores
and dirs-sys
#8048
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
use core::fmt; | ||
|
||
use fs_err as fs; | ||
use std::ffi::OsString; | ||
|
||
use uv_pep440::Version; | ||
use uv_pep508::{InvalidNameError, PackageName}; | ||
|
@@ -354,6 +354,15 @@ impl fmt::Display for InstalledTool { | |
} | ||
} | ||
|
||
fn is_absolute_path(path: OsString) -> Option<PathBuf> { | ||
let path = PathBuf::from(path); | ||
if path.is_absolute() { | ||
Some(path) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
/// Find a directory to place executables in. | ||
/// | ||
/// This follows, in order: | ||
|
@@ -368,20 +377,16 @@ impl fmt::Display for InstalledTool { | |
/// Errors if a directory cannot be found. | ||
pub fn find_executable_directory() -> Result<PathBuf, Error> { | ||
std::env::var_os(EnvVars::UV_TOOL_BIN_DIR) | ||
.and_then(dirs_sys::is_absolute_path) | ||
.or_else(|| std::env::var_os(EnvVars::XDG_BIN_HOME).and_then(dirs_sys::is_absolute_path)) | ||
.and_then(is_absolute_path) | ||
.or_else(|| std::env::var_os(EnvVars::XDG_BIN_HOME).and_then(is_absolute_path)) | ||
.or_else(|| { | ||
std::env::var_os(EnvVars::XDG_DATA_HOME) | ||
.and_then(dirs_sys::is_absolute_path) | ||
.and_then(is_absolute_path) | ||
.map(|path| path.join("../bin")) | ||
}) | ||
.or_else(|| { | ||
// See https://github.com/dirs-dev/dirs-rs/blob/50b50f31f3363b7656e5e63b3fa1060217cbc844/src/win.rs#L5C58-L5C78 | ||
#[cfg(windows)] | ||
let home_dir = dirs_sys::known_folder_profile(); | ||
#[cfg(not(windows))] | ||
let home_dir = dirs_sys::home_dir(); | ||
home_dir.map(|path| path.join(".local").join("bin")) | ||
let home_dir = etcetera::home_dir(); | ||
home_dir.map(|path| path.join(".local").join("bin")).ok() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be mostly the same except that it defers to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that's unfortunate. What's your suggestion? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like we already depend on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zanieb -- I think my preference here is just to ship this as part of 0.5.0 in the near-ish future, and accept that we now respect non-empty |
||
}) | ||
.ok_or(Error::NoExecutableDirectory) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this isn't quite the same. It looks like etcetera will use local
AppData
and then falls back to RoamingAppData
, whereas the above always uses the Roaming version?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dirs-sys
uses theKnownFolderID
FOLDERID_RoamingAppData
, whileetcetera
uses theCSIDL
CSIDL_APPDATA
. AndFOLDERID_RoamingAppData
is equivalent toCSIDL_APPDATA
in CSIDL.If the
SHGetFolderPathW
call fails, etcetera will fall back to useself.home_dir.join("AppData").join("Roaming")
. So it seems etcetera always uses the Roaming APPDATA too, they should be the same.