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

Pax | Switching key to u8 and update on Pax header doc header #391

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
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])>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately we already published the previous PR, we can't break the API. We could add a new one...but I'm not sure, maybe we only do it if there's an actual use case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's better like that I think.
If needed one day, this PR could be merged to fix the issue later

) -> 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