|
2 | 2 | pub fn find_libc_paths() -> anyhow::Result<Vec<std::path::PathBuf>> { |
3 | 3 | use itertools::Itertools; |
4 | 4 |
|
5 | | - let mut paths = vec![ |
6 | | - "/lib/x86_64-linux-gnu/libc.so.6".into(), |
7 | | - "/usr/lib/x86_64-linux-gnu/libc.so.6".into(), |
8 | | - "/lib64/libc.so.6".into(), |
9 | | - "/usr/lib64/libc.so.6".into(), |
| 5 | + let patterns = [ |
| 6 | + // Debian, Ubuntu: Standard Linux multiarch paths |
| 7 | + "/lib/*-linux-gnu/libc.so.6", |
| 8 | + "/usr/lib/*-linux-gnu/libc.so.6", |
| 9 | + // RHEL, Fedora, CentOS, Arch: |
| 10 | + "/lib*/libc.so.6", |
| 11 | + "/usr/lib*/libc.so.6", |
| 12 | + // NixOS: find all glibc versions in the Nix store |
| 13 | + "/nix/store/*glibc*/lib/libc.so.6", |
10 | 14 | ]; |
11 | 15 |
|
12 | | - // On NixOS, try to find all glibc versions in the Nix store |
13 | | - if let Ok(entries) = std::fs::read_dir("/nix/store") { |
14 | | - let nix_paths: Vec<_> = entries |
15 | | - .filter_map(|entry| { |
16 | | - let Ok(entry) = entry else { return None }; |
17 | | - |
18 | | - let path = entry.path(); |
19 | | - let file_name = path.file_name()?; |
20 | | - let name = file_name.to_string_lossy(); |
21 | | - |
22 | | - // Look for glibc directories |
23 | | - if name.contains("glibc") && !name.contains("locales") && !name.contains("iconv") { |
24 | | - return Some(path.join("lib").join("libc.so.6")); |
25 | | - } |
26 | | - None |
27 | | - }) |
28 | | - .collect(); |
29 | | - |
30 | | - paths.extend(nix_paths); |
31 | | - } |
32 | | - |
33 | | - let existing_paths = paths |
34 | | - .into_iter() |
| 16 | + let existing_paths = patterns |
| 17 | + .iter() |
| 18 | + .flat_map(|pattern| glob::glob(pattern).ok()) |
| 19 | + .flatten() |
| 20 | + .filter_map(|p| p.ok()) |
35 | 21 | .filter_map(|p| p.canonicalize().ok()) |
36 | 22 | .filter(|path| { |
37 | 23 | let Ok(metadata) = std::fs::metadata(path) else { |
|
0 commit comments