diff --git a/src/fetch_ld.rs b/src/fetch_ld.rs index bd323d5..c5199c4 100644 --- a/src/fetch_ld.rs +++ b/src/fetch_ld.rs @@ -36,6 +36,6 @@ pub fn fetch_ld(ver: &LibcVersion) -> Result { }; let out_name = format!("ld-{}.so", ver.string_short); - libc_deb::write_ubuntu_pkg_file(&deb_file_name, &ld_name, out_name).context(DebSnafu)?; + libc_deb::write_ubuntu_pkg_file(&deb_file_name, &[&ld_name], out_name).context(DebSnafu)?; Ok(()) } diff --git a/src/libc_deb.rs b/src/libc_deb.rs index 22e3f57..9950946 100644 --- a/src/libc_deb.rs +++ b/src/libc_deb.rs @@ -18,16 +18,24 @@ pub static PKG_URL: &str = "https://launchpad.net/ubuntu/+archive/primary/+files pub type Result = std::result::Result; + /// Helper function that decides whether the tar file `entry` matches -/// `file_name` -fn tar_entry_matches(entry: &std::io::Result>, file_name: &str) -> bool { - match entry { - Ok(entry) => match entry.path() { - Ok(path) => path.file_name() == Some(file_name.as_ref()), - Err(_) => false, - }, - Err(_) => false, +/// `file_name` form the list of `file_names` +fn tar_entry_matches_any(entry: &std::io::Result>, file_names: &[&str]) -> bool { + let Ok(entry) = entry else { return false }; + let Ok(path) = entry.path() else { return false }; + + let res = path.file_name() + .and_then(|name| name.to_str()) + .map(|name| file_names.contains(&name)) + .unwrap_or(false); + if res { + println!( + "{}", + format!("Found matching file: {}", path.display()).bold().green() + ); } + res } #[derive(Debug, Snafu)] @@ -96,7 +104,7 @@ fn request_ubuntu_pkg(deb_file_name: &str) -> Result>( deb_file_name: &str, - file_name: &str, + file_names: &[&str], out_path: P, ) -> Result<()> { let out_path = out_path.as_ref(); @@ -122,15 +130,15 @@ pub fn write_ubuntu_pkg_file>( match ext { b"gz" => { let data = GzDecoder::new(entry); - write_ubuntu_data_tar_file(data, file_name, out_path) + write_ubuntu_data_tar_file(data, file_names, out_path) } b"xz" => { let data = LzmaReader::new_decompressor(entry).context(DataUnzipLzmaSnafu)?; - write_ubuntu_data_tar_file(data, file_name, out_path) + write_ubuntu_data_tar_file(data, file_names, out_path) } b"zst" => { let data = zstd::stream::read::Decoder::new(entry).context(DataUnzipZstdSnafu)?; - write_ubuntu_data_tar_file(data, file_name, out_path) + write_ubuntu_data_tar_file(data, file_names, out_path) } ext => None.context(DataExtSnafu { ext }), }?; @@ -145,14 +153,14 @@ pub fn write_ubuntu_pkg_file>( /// and extract the file. fn write_ubuntu_data_tar_file( data_tar_bytes: R, - file_name: &str, + file_names: &[&str], out_path: &Path, ) -> Result<()> { let mut data_tar = tar::Archive::new(data_tar_bytes); let mut entry = data_tar .entries() .context(DataEntriesSnafu)? - .find(|entry| tar_entry_matches(entry, file_name)) + .find(|entry| tar_entry_matches_any(entry, &file_names)) .context(FileNotFoundSnafu)? .context(ReadSnafu)?; let mut out_file = File::create(out_path).context(CreateSnafu)?; diff --git a/src/unstrip_libc.rs b/src/unstrip_libc.rs index eeb03c7..9778652 100644 --- a/src/unstrip_libc.rs +++ b/src/unstrip_libc.rs @@ -58,14 +58,14 @@ fn do_unstrip_libc(libc: &Path, ver: &LibcVersion) -> Result { let sym_path = tmp_dir.path().join("libc-syms"); - let name = if version_compare::compare_to(&ver.string_short, "2.34", Cmp::Lt).unwrap() { - format!("libc-{}.so", ver.string_short) - } else { + let name1 = format!("libc-{}.so", ver.string_short); + let name2 = { let build_id = elf::get_build_id(libc).context(ElfParseSnafu)?; build_id.chars().skip(2).collect::() + ".debug" }; - - libc_deb::write_ubuntu_pkg_file(&deb_file_name, &name, &sym_path).context(DebSnafu)?; + let names = vec![name1.as_str(), name2.as_str()]; + + libc_deb::write_ubuntu_pkg_file(&deb_file_name, names.as_slice(), &sym_path).context(DebSnafu)?; let out = Command::new("eu-unstrip") .arg(libc)