Skip to content

Commit

Permalink
Switching key to u8 and update on Pax header doc header and fmt fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gwitrand-ovh committed Nov 25, 2024
1 parent 2064e86 commit c37a518
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/pax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl<'entry> PaxExtension<'entry> {
}
}

/// Extension trait for `Builder` to append PAX extended headers.
/// Implement `Builder` to append PAX extended headers.
impl<T: Write> crate::Builder<T> {
/// Append PAX extended headers to the archive.
///
Expand All @@ -156,7 +156,7 @@ impl<T: Write> crate::Builder<T> {
/// Returns io::Error if an error occurs, else it returns ()
pub fn append_pax_extensions<'key, 'value>(
&mut self,
headers: impl IntoIterator<Item = (&'key str, &'value [u8])>,
headers: impl IntoIterator<Item = (&'key [u8], &'value [u8])>,
) -> Result<(), io::Error> {
// Store the headers formatted before write
let mut data: Vec<u8> = Vec::new();
Expand All @@ -172,7 +172,9 @@ impl<T: Write> crate::Builder<T> {
max_len *= 10;
}
let len = rest_len + len_len;
write!(&mut data, "{} {}=", len, key)?;
write!(&mut data, "{} ", len)?;
data.extend_from_slice(key);
data.push(b'=');
data.extend_from_slice(value);
data.push(b'\n');
}
Expand Down
12 changes: 9 additions & 3 deletions tests/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,8 +933,11 @@ fn pax_simple_write() {
let mut ar: Builder<BufWriter<File>> = Builder::new(BufWriter::new(file));

let pax_extensions = [
("arbitrary_pax_key", b"arbitrary_pax_value".as_slice()),
("SCHILY.xattr.security.selinux", b"foo_t"),
(
b"arbitrary_pax_key".as_slice(),
b"arbitrary_pax_value".as_slice(),
),
(b"SCHILY.xattr.security.selinux".as_slice(), b"foo_t"),
];

t!(ar.append_pax_extensions(pax_extensions));
Expand All @@ -953,7 +956,10 @@ fn pax_simple_write() {
assert_eq!(pax_arbitrary.key(), Ok("arbitrary_pax_key"));
assert_eq!(pax_arbitrary.value(), Ok("arbitrary_pax_value"));
let xattr = t!(pax_headers.next().unwrap());
assert_eq!(xattr.key().unwrap(), pax_extensions[1].0);
assert_eq!(
xattr.key().unwrap(),
std::str::from_utf8(pax_extensions[1].0).unwrap()
);
assert_eq!(xattr.value_bytes(), pax_extensions[1].1);

assert!(entries.next().is_none());
Expand Down

0 comments on commit c37a518

Please sign in to comment.