Skip to content

Commit 7b6ad3a

Browse files
polka125io12
authored andcommitted
fix unstrip_libc
1 parent bb47505 commit 7b6ad3a

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

src/fetch_ld.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ pub fn fetch_ld(ver: &LibcVersion) -> Result {
3636
};
3737
let out_name = format!("ld-{}.so", ver.string_short);
3838

39-
libc_deb::write_ubuntu_pkg_file(&deb_file_name, &ld_name, out_name).context(DebSnafu)?;
39+
libc_deb::write_ubuntu_pkg_file(&deb_file_name, &[&ld_name], out_name).context(DebSnafu)?;
4040
Ok(())
4141
}

src/libc_deb.rs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,28 @@ pub static PKG_URL: &str = "https://launchpad.net/ubuntu/+archive/primary/+files
1919
pub type Result<T> = std::result::Result<T, Error>;
2020

2121
/// Helper function that decides whether the tar file `entry` matches
22-
/// `file_name`
23-
fn tar_entry_matches<R: Read>(entry: &std::io::Result<tar::Entry<R>>, file_name: &str) -> bool {
24-
match entry {
25-
Ok(entry) => match entry.path() {
26-
Ok(path) => path.file_name() == Some(file_name.as_ref()),
27-
Err(_) => false,
28-
},
29-
Err(_) => false,
22+
/// one of the `file_names`
23+
fn tar_entry_matches_any<R: Read>(
24+
entry: &std::io::Result<tar::Entry<R>>,
25+
file_names: &[&str],
26+
) -> bool {
27+
let Ok(entry) = entry else { return false };
28+
let Ok(path) = entry.path() else { return false };
29+
30+
let res = path
31+
.file_name()
32+
.and_then(|name| name.to_str())
33+
.map(|name| file_names.contains(&name))
34+
.unwrap_or(false);
35+
if res {
36+
println!(
37+
"{}",
38+
format!("Found matching file: {}", path.display())
39+
.bold()
40+
.green()
41+
);
3042
}
43+
res
3144
}
3245

3346
#[derive(Debug, Snafu)]
@@ -96,7 +109,7 @@ fn request_ubuntu_pkg(deb_file_name: &str) -> Result<reqwest::blocking::Response
96109
/// extract the file.
97110
pub fn write_ubuntu_pkg_file<P: AsRef<Path>>(
98111
deb_file_name: &str,
99-
file_name: &str,
112+
file_names: &[&str],
100113
out_path: P,
101114
) -> Result<()> {
102115
let out_path = out_path.as_ref();
@@ -122,15 +135,15 @@ pub fn write_ubuntu_pkg_file<P: AsRef<Path>>(
122135
match ext {
123136
b"gz" => {
124137
let data = GzDecoder::new(entry);
125-
write_ubuntu_data_tar_file(data, file_name, out_path)
138+
write_ubuntu_data_tar_file(data, file_names, out_path)
126139
}
127140
b"xz" => {
128141
let data = LzmaReader::new_decompressor(entry).context(DataUnzipLzmaSnafu)?;
129-
write_ubuntu_data_tar_file(data, file_name, out_path)
142+
write_ubuntu_data_tar_file(data, file_names, out_path)
130143
}
131144
b"zst" => {
132145
let data = zstd::stream::read::Decoder::new(entry).context(DataUnzipZstdSnafu)?;
133-
write_ubuntu_data_tar_file(data, file_name, out_path)
146+
write_ubuntu_data_tar_file(data, file_names, out_path)
134147
}
135148
ext => None.context(DataExtSnafu { ext }),
136149
}?;
@@ -145,14 +158,14 @@ pub fn write_ubuntu_pkg_file<P: AsRef<Path>>(
145158
/// and extract the file.
146159
fn write_ubuntu_data_tar_file<R: Read>(
147160
data_tar_bytes: R,
148-
file_name: &str,
161+
file_names: &[&str],
149162
out_path: &Path,
150163
) -> Result<()> {
151164
let mut data_tar = tar::Archive::new(data_tar_bytes);
152165
let mut entry = data_tar
153166
.entries()
154167
.context(DataEntriesSnafu)?
155-
.find(|entry| tar_entry_matches(entry, file_name))
168+
.find(|entry| tar_entry_matches_any(entry, file_names))
156169
.context(FileNotFoundSnafu)?
157170
.context(ReadSnafu)?;
158171
let mut out_file = File::create(out_path).context(CreateSnafu)?;

src/unstrip_libc.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use ex::io;
1616
use snafu::ResultExt;
1717
use snafu::Snafu;
1818
use tempfile::TempDir;
19-
use version_compare::Cmp;
2019

2120
#[derive(Debug, Snafu)]
2221
#[allow(clippy::enum_variant_names)]
@@ -58,14 +57,15 @@ fn do_unstrip_libc(libc: &Path, ver: &LibcVersion) -> Result {
5857

5958
let sym_path = tmp_dir.path().join("libc-syms");
6059

61-
let name = if version_compare::compare_to(&ver.string_short, "2.34", Cmp::Lt).unwrap() {
62-
format!("libc-{}.so", ver.string_short)
63-
} else {
60+
let name1 = format!("libc-{}.so", ver.string_short);
61+
let name2 = {
6462
let build_id = elf::get_build_id(libc).context(ElfParseSnafu)?;
6563
build_id.chars().skip(2).collect::<String>() + ".debug"
6664
};
65+
let names = [name1.as_str(), name2.as_str()];
6766

68-
libc_deb::write_ubuntu_pkg_file(&deb_file_name, &name, &sym_path).context(DebSnafu)?;
67+
libc_deb::write_ubuntu_pkg_file(&deb_file_name, names.as_slice(), &sym_path)
68+
.context(DebSnafu)?;
6969

7070
let out = Command::new("eu-unstrip")
7171
.arg(libc)

0 commit comments

Comments
 (0)