Skip to content

Commit

Permalink
Read the linkpath PAX extension (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
nullpo-head committed Jul 12, 2021
1 parent 065368b commit 6fa206d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
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.

0 comments on commit 6fa206d

Please sign in to comment.