mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Merge PR #15136: fix(linux): honor loader separators in library preflight
This commit is contained in:
commit
04c06d15c7
1 file changed
+48
-2
@@ -227,7 +227,14 @@ pub fn missing_message(session: DisplaySession, missing: &[AnyOf], distro: Distr
|
||||
|
||||
/// Library directories to search: `LD_LIBRARY_PATH`, then the usual system and Flatpak paths.
|
||||
fn search_dirs(ld_library_path: Option<&str>) -> Vec<PathBuf> {
|
||||
let mut dirs: Vec<PathBuf> = ld_library_path.unwrap_or("").split(':').filter(|d| !d.is_empty()).map(PathBuf::from).collect();
|
||||
// ld.so accepts either separator; an empty entry in a nonempty list means the current directory.
|
||||
// An unset or entirely empty variable adds no directories.
|
||||
let mut dirs: Vec<PathBuf> = ld_library_path
|
||||
.filter(|value| !value.is_empty())
|
||||
.into_iter()
|
||||
.flat_map(|value| value.split([':', ';']))
|
||||
.map(|dir| PathBuf::from(if dir.is_empty() { "." } else { dir }))
|
||||
.collect();
|
||||
let triplet = if cfg!(target_arch = "aarch64") {
|
||||
"aarch64-linux-gnu"
|
||||
} else if cfg!(target_arch = "riscv64") {
|
||||
@@ -398,7 +405,8 @@ mod tests {
|
||||
fn library_dirs_count_and_unread_cache_is_inconclusive() {
|
||||
let dirs = search_dirs(Some("/opt/x/lib::/nix/store/abc/lib"));
|
||||
assert_eq!(dirs[0], PathBuf::from("/opt/x/lib"));
|
||||
assert_eq!(dirs[1], PathBuf::from("/nix/store/abc/lib"));
|
||||
assert_eq!(dirs[1], PathBuf::from("."));
|
||||
assert_eq!(dirs[2], PathBuf::from("/nix/store/abc/lib"));
|
||||
// Found by file in a directory (no ldconfig, as on NixOS).
|
||||
let probe = Probe { ldconfig: None, dirs: vec![PathBuf::from("/nix/lib")] };
|
||||
let present = ["/nix/lib/libwayland-client.so.0", "/nix/lib/libxkbcommon.so.0", "/nix/lib/libEGL.so.1"];
|
||||
@@ -412,6 +420,44 @@ mod tests {
|
||||
assert!(msg.contains("dnf install libwayland-client libxkbcommon vulkan-loader"), "{msg}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn library_path_separators_and_empty_entries_follow_the_loader() {
|
||||
let defaults = search_dirs(None);
|
||||
assert_eq!(search_dirs(Some("")), defaults, "an entirely empty variable adds no directories");
|
||||
for (value, entries) in [
|
||||
("/opt/a:/opt/b", &["/opt/a", "/opt/b"][..]),
|
||||
("/opt/a;/opt/b", &["/opt/a", "/opt/b"][..]),
|
||||
("/opt/a;/opt/b:/opt/c", &["/opt/a", "/opt/b", "/opt/c"][..]),
|
||||
(":/opt/b", &[".", "/opt/b"][..]),
|
||||
("/opt/a:", &["/opt/a", "."][..]),
|
||||
("/opt/a::/opt/b", &["/opt/a", ".", "/opt/b"][..]),
|
||||
("/opt/a;;/opt/b", &["/opt/a", ".", "/opt/b"][..]),
|
||||
(":", &[".", "."][..]),
|
||||
(";", &[".", "."][..]),
|
||||
(" /opt/a ;relative/lib", &[" /opt/a ", "relative/lib"][..]),
|
||||
(" ", &[" "][..]),
|
||||
] {
|
||||
let mut expected: Vec<PathBuf> = entries.iter().map(PathBuf::from).collect();
|
||||
expected.extend(defaults.iter().cloned());
|
||||
assert_eq!(search_dirs(Some(value)), expected, "LD_LIBRARY_PATH={value:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn loader_search_paths_prevent_false_startup_errors() {
|
||||
let soname = "libxkbcommon-x11.so.0";
|
||||
let names: Vec<&str> = ALL_X11.iter().copied().filter(|name| *name != soname).collect();
|
||||
let probe = Probe { ldconfig: Some(cache_for_this_arch(&names)), dirs: search_dirs(None) };
|
||||
let missing = check(DisplaySession::X11, &probe, |_| false);
|
||||
assert!(decide(DisplaySession::X11, missing, || Distro::Debian).is_err(), "a genuinely missing library still blocks startup");
|
||||
for (value, directory) in [("/opt/a;/opt/b", "/opt/b"), (":/opt/a", "."), ("/opt/a:", ".")] {
|
||||
let probe = Probe { ldconfig: Some(cache_for_this_arch(&names)), dirs: search_dirs(Some(value)) };
|
||||
let present = Path::new(directory).join(soname);
|
||||
let verdict = check(DisplaySession::X11, &probe, |path| path == present);
|
||||
assert_eq!(decide(DisplaySession::X11, verdict, || Distro::Debian), Ok(()), "LD_LIBRARY_PATH={value:?}, library at {}", present.display());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unreadable_cache_never_warns_or_fails() {
|
||||
// Issue #1144: Alpine (musl) has no `ldconfig -p`, so a library that exists was reported missing.
|
||||
|
||||
Reference in new issue
Block a user