From 6cddceb37a022fdb27bc47ebf040d36718159c47 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 13 Sep 2025 12:33:40 +0200 Subject: [PATCH] config_paths: use immutable/SSA style for determining config paths This logic is extremely confusing because it creates a ConfigPaths object only to throw it away later. Fix that. --- src/env/config_paths.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/env/config_paths.rs b/src/env/config_paths.rs index 3c207dd01..69624b568 100644 --- a/src/env/config_paths.rs +++ b/src/env/config_paths.rs @@ -5,7 +5,6 @@ /// A struct of configuration directories, determined in main() that fish will optionally pass to /// env_init. -#[derive(Default)] pub struct ConfigPaths { pub sysconf: PathBuf, // e.g., /usr/local/etc pub bin: Option, // e.g., /usr/local/bin @@ -115,27 +114,28 @@ fn new(argv0: &Path, exec_path: PathBuf) -> Self { }; } - let mut paths = ConfigPaths::default(); // The next check is that we are in a relocatable directory tree if exec_path.ends_with("bin/fish") { let base_path = exec_path.parent().unwrap().parent().unwrap(); - paths = ConfigPaths { - sysconf: base_path.join("etc/fish"), - bin: Some(base_path.join("bin")), - data: base_path.join("share/fish"), - doc: base_path.join("share/doc/fish"), - locale: base_path.join("share/locale"), + let data = base_path.join("share/fish"); + let sysconf = base_path.join("etc/fish"); + if data.exists() && sysconf.exists() { + let doc = base_path.join("share/doc/fish"); + return ConfigPaths { + sysconf, + bin: Some(base_path.join("bin")), + data, + // The docs dir may not exist; in that case fall back to the compiled in path. + doc: if doc.exists() { + doc + } else { + PathBuf::from(DOC_DIR) + }, + locale: base_path.join("share/locale"), + }; } } - if paths.data.exists() && paths.sysconf.exists() { - // The docs dir may not exist; in that case fall back to the compiled in path. - if !paths.doc.exists() { - paths.doc = PathBuf::from(DOC_DIR); - } - return paths; - } - Self::static_paths() } }