From 7827a8e533fd8465c4f891037099e9094f033415 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Tue, 19 Nov 2024 19:53:49 +0100 Subject: [PATCH] Make bin path an Option It is possible we cannot acquire this --- src/bin/fish.rs | 14 +++++++++----- src/env/environment.rs | 14 +++++++++----- src/env/var.rs | 8 ++++---- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/bin/fish.rs b/src/bin/fish.rs index 59cc6fe31..671e15496 100644 --- a/src/bin/fish.rs +++ b/src/bin/fish.rs @@ -167,7 +167,7 @@ fn determine_config_directory_paths(argv0: impl AsRef) -> ConfigPaths { data: manifest_dir.join("share"), sysconf: manifest_dir.join("etc"), doc: manifest_dir.join("user_doc/html"), - bin: exec_path.parent().unwrap().to_owned(), + bin: Some(exec_path.parent().unwrap().to_owned()), } } @@ -179,7 +179,7 @@ fn determine_config_directory_paths(argv0: impl AsRef) -> ConfigPaths { data: base_path.join("share/fish"), sysconf: base_path.join("etc/fish"), doc: base_path.join("share/doc/fish"), - bin: base_path.join("bin"), + bin: Some(base_path.join("bin")), } } else if exec_path.ends_with("fish") { FLOG!( @@ -191,7 +191,7 @@ fn determine_config_directory_paths(argv0: impl AsRef) -> ConfigPaths { data: base_path.join("share"), sysconf: base_path.join("etc"), doc: base_path.join("user_doc/html"), - bin: base_path.to_path_buf(), + bin: Some(base_path.to_path_buf()), } } @@ -212,7 +212,7 @@ fn determine_config_directory_paths(argv0: impl AsRef) -> ConfigPaths { data: PathBuf::from(DATA_DIR).join("fish"), sysconf: PathBuf::from(SYSCONF_DIR).join("fish"), doc: DOC_DIR.into(), - bin: BIN_DIR.into(), + bin: Some(BIN_DIR.into()), } } @@ -223,7 +223,11 @@ fn determine_config_directory_paths(argv0: impl AsRef) -> ConfigPaths { paths.data.display().to_string(), paths.sysconf.display().to_string(), paths.doc.display().to_string(), - paths.bin.display().to_string() + paths + .bin + .clone() + .map(|x| x.display().to_string()) + .unwrap_or("|not found|".to_string()), ); paths diff --git a/src/env/environment.rs b/src/env/environment.rs index 29331c765..05fa97deb 100644 --- a/src/env/environment.rs +++ b/src/env/environment.rs @@ -611,11 +611,15 @@ pub fn env_init(paths: Option<&ConfigPaths>, do_uvars: bool, default_paths: bool EnvMode::GLOBAL, str2wcstring(paths.doc.as_os_str().as_bytes()), ); - vars.set_one( - FISH_BIN_DIR, - EnvMode::GLOBAL, - str2wcstring(paths.bin.as_os_str().as_bytes()), - ); + if let Some(bp) = &paths.bin { + vars.set_one( + FISH_BIN_DIR, + EnvMode::GLOBAL, + str2wcstring(bp.as_os_str().as_bytes()), + ); + } else { + vars.set_empty(FISH_BIN_DIR, EnvMode::GLOBAL); + }; if default_paths { let mut scstr = paths.data.clone(); diff --git a/src/env/var.rs b/src/env/var.rs index 937362f99..9e8f10e62 100644 --- a/src/env/var.rs +++ b/src/env/var.rs @@ -50,10 +50,10 @@ impl From for u16 { /// env_init. #[derive(Default)] pub struct ConfigPaths { - pub data: PathBuf, // e.g., /usr/local/share - pub sysconf: PathBuf, // e.g., /usr/local/etc - pub doc: PathBuf, // e.g., /usr/local/share/doc/fish - pub bin: PathBuf, // e.g., /usr/local/bin + pub data: PathBuf, // e.g., /usr/local/share + pub sysconf: PathBuf, // e.g., /usr/local/etc + pub doc: PathBuf, // e.g., /usr/local/share/doc/fish + pub bin: Option, // e.g., /usr/local/bin } /// A collection of status and pipestatus.