Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support long symbolic/hard link path name by reading the linkpath PAX extension #252

Merged
merged 1 commit into from Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/entry.rs
Expand Up @@ -334,7 +334,18 @@ impl<'a> EntryFields<'a> {
Some(Cow::Borrowed(bytes))
}
}
None => self.header.link_name_bytes(),
None => {
if let Some(ref pax) = self.pax_extensions {
let pax = pax_extensions(pax)
.filter_map(|f| f.ok())
.find(|f| f.key_bytes() == b"linkpath")
.map(|f| f.value_bytes());
if let Some(field) = pax {
return Some(Cow::Borrowed(field));
}
}
self.header.link_name_bytes()
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions tests/all.rs
Expand Up @@ -791,6 +791,22 @@ fn pax_path() {
assert!(first.path().unwrap().ends_with("aaaaaaaaaaaaaaa"));
}

#[test]
fn pax_linkpath() {
let mut ar = Archive::new(tar!("pax2.tar"));
let mut links = t!(ar.entries()).skip(3).take(2);

let long_symlink = t!(links.next().unwrap());
let link_name = long_symlink.link_name().unwrap().unwrap();
assert!(link_name.to_str().unwrap().len() > 99);
assert!(link_name.ends_with("bbbbbbbbbbbbbbb"));

let long_hardlink = t!(links.next().unwrap());
let link_name = long_hardlink.link_name().unwrap().unwrap();
assert!(link_name.to_str().unwrap().len() > 99);
assert!(link_name.ends_with("ccccccccccccccc"));
}

#[test]
fn long_name_trailing_nul() {
let mut b = Builder::new(Vec::<u8>::new());
Expand Down
Binary file modified tests/archives/pax2.tar
Binary file not shown.