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

Use var_os instead of `var #1223

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/var-os.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fnm": patch
---

Allow reading non-unicode paths from environment variables
26 changes: 14 additions & 12 deletions src/commands/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,20 @@ fn warn_if_multishell_path_not_in_path_env_var(
multishell_path: &std::path::Path,
config: &FnmConfig,
) {
let bin_path = if cfg!(unix) {
multishell_path.join("bin")
} else {
multishell_path.to_path_buf()
};

let fixed_path = bin_path.to_str().and_then(shell::maybe_fix_windows_path);
let fixed_path = fixed_path.as_ref().map(|x| &x[..]);

for path in std::env::split_paths(&std::env::var("PATH").unwrap_or_default()) {
if bin_path == path || fixed_path == path.to_str() {
return;
if let Some(path_var) = std::env::var_os("PATH") {
let bin_path = if cfg!(unix) {
multishell_path.join("bin")
} else {
multishell_path.to_path_buf()
};

let fixed_path = bin_path.to_str().and_then(shell::maybe_fix_windows_path);
let fixed_path = fixed_path.as_deref();

for path in std::env::split_paths(&path_var) {
if bin_path == path || fixed_path == path.to_str() {
return;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/directories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::path_ext::PathExt;

fn xdg_dir(env: &str) -> Option<PathBuf> {
if cfg!(windows) {
let env_var = std::env::var(env).ok()?;
let env_var = std::env::var_os(env)?;
Some(PathBuf::from(env_var))
} else {
// On non-Windows platforms, `etcetera` already handles XDG variables
Expand Down
Loading