Make bin path an Option

It is possible we cannot acquire this
This commit is contained in:
Fabian Boehm 2024-11-19 19:53:49 +01:00
parent aa30b4db4b
commit 7827a8e533
3 changed files with 22 additions and 14 deletions

View file

@ -167,7 +167,7 @@ fn determine_config_directory_paths(argv0: impl AsRef<Path>) -> 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<Path>) -> 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<Path>) -> 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<Path>) -> 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<Path>) -> 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

View file

@ -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()),
);
if let Some(bp) = &paths.bin {
vars.set_one(
FISH_BIN_DIR,
EnvMode::GLOBAL,
str2wcstring(paths.bin.as_os_str().as_bytes()),
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();

2
src/env/var.rs vendored
View file

@ -53,7 +53,7 @@ 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 bin: Option<PathBuf>, // e.g., /usr/local/bin
}
/// A collection of status and pipestatus.