Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/fetch_ld.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
36 changes: 22 additions & 14 deletions src/libc_deb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,24 @@ pub static PKG_URL: &str = "https://launchpad.net/ubuntu/+archive/primary/+files

pub type Result<T> = std::result::Result<T, Error>;


/// Helper function that decides whether the tar file `entry` matches
/// `file_name`
fn tar_entry_matches<R: Read>(entry: &std::io::Result<tar::Entry<R>>, 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<R: Read>(entry: &std::io::Result<tar::Entry<R>>, 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)]
Expand Down Expand Up @@ -96,7 +104,7 @@ fn request_ubuntu_pkg(deb_file_name: &str) -> Result<reqwest::blocking::Response
/// extract the file.
pub fn write_ubuntu_pkg_file<P: AsRef<Path>>(
deb_file_name: &str,
file_name: &str,
file_names: &[&str],
out_path: P,
) -> Result<()> {
let out_path = out_path.as_ref();
Expand All @@ -122,15 +130,15 @@ pub fn write_ubuntu_pkg_file<P: AsRef<Path>>(
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 }),
}?;
Expand All @@ -145,14 +153,14 @@ pub fn write_ubuntu_pkg_file<P: AsRef<Path>>(
/// and extract the file.
fn write_ubuntu_data_tar_file<R: Read>(
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)?;
Expand Down
10 changes: 5 additions & 5 deletions src/unstrip_libc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<String>() + ".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)
Expand Down