Skip to content

Commit e5f83cd

Browse files
pcckrobelus
authored andcommitted
Fix logic for relocatable directory trees
The existing logic did not work because: - Path::new("/foo/bar").ends_with("/bar") does not return true. - PathBuf::shrink_to() only (potentially) reallocates the backing storage, and won't have an effect on the stored value.
1 parent a1d44a9 commit e5f83cd

File tree

1 file changed

+22
-38
lines changed

1 file changed

+22
-38
lines changed

src/bin/fish.rs

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -174,50 +174,34 @@ fn determine_config_directory_paths(argv0: impl AsRef<Path>) -> ConfigPaths {
174174

175175
if !done {
176176
// The next check is that we are in a reloctable directory tree
177-
let installed_suffix = Path::new("/bin/fish");
178-
let just_a_fish = Path::new("/fish");
179-
let suffix = if exec_path.ends_with(installed_suffix) {
180-
Some(installed_suffix)
181-
} else if exec_path.ends_with(just_a_fish) {
177+
if exec_path.ends_with("bin/fish") {
178+
let base_path = exec_path.parent().unwrap().parent().unwrap();
179+
paths = ConfigPaths {
180+
data: base_path.join("share/fish"),
181+
sysconf: base_path.join("etc/fish"),
182+
doc: base_path.join("share/doc/fish"),
183+
bin: base_path.join("bin"),
184+
}
185+
} else if exec_path.ends_with("fish") {
182186
FLOG!(
183187
config,
184188
"'fish' not in a 'bin/', trying paths relative to source tree"
185189
);
186-
Some(just_a_fish)
187-
} else {
188-
None
189-
};
190-
191-
if let Some(suffix) = suffix {
192-
let seems_installed = suffix == installed_suffix;
193-
194-
let mut base_path = exec_path;
195-
base_path.shrink_to(base_path.as_os_str().len() - suffix.as_os_str().len());
196-
let base_path = base_path;
197-
198-
paths = if seems_installed {
199-
ConfigPaths {
200-
data: base_path.join("share/fish"),
201-
sysconf: base_path.join("etc/fish"),
202-
doc: base_path.join("share/doc/fish"),
203-
bin: base_path.join("bin"),
204-
}
205-
} else {
206-
ConfigPaths {
207-
data: base_path.join("share"),
208-
sysconf: base_path.join("etc"),
209-
doc: base_path.join("user_doc/html"),
210-
bin: base_path,
211-
}
212-
};
190+
let base_path = exec_path.parent().unwrap();
191+
paths = ConfigPaths {
192+
data: base_path.join("share"),
193+
sysconf: base_path.join("etc"),
194+
doc: base_path.join("user_doc/html"),
195+
bin: base_path.to_path_buf(),
196+
}
197+
}
213198

214-
if paths.data.exists() && paths.sysconf.exists() {
215-
// The docs dir may not exist; in that case fall back to the compiled in path.
216-
if !paths.doc.exists() {
217-
paths.doc = PathBuf::from(DOC_DIR);
218-
}
219-
done = true;
199+
if paths.data.exists() && paths.sysconf.exists() {
200+
// The docs dir may not exist; in that case fall back to the compiled in path.
201+
if !paths.doc.exists() {
202+
paths.doc = PathBuf::from(DOC_DIR);
220203
}
204+
done = true;
221205
}
222206
}
223207
}

0 commit comments

Comments
 (0)