Skip to content

Commit

Permalink
Merge pull request ostreedev#220 from lucab/ups/tar-mode-mask
Browse files Browse the repository at this point in the history
tar/export: fix mode bits in tar archive
  • Loading branch information
cgwalters authored Jan 26, 2022
2 parents 8274bd0 + cde864b commit e8282c6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/src/tar/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl<'a, W: std::io::Write> OstreeTarWriter<'a, W> {
h.set_uid(meta.attribute_uint32("unix::uid") as u64);
h.set_gid(meta.attribute_uint32("unix::gid") as u64);
let mode = meta.attribute_uint32("unix::mode");
h.set_mode(mode);
h.set_mode(mode & !libc::S_IFMT);
let mut target_header = h.clone();
target_header.set_size(0);

Expand Down Expand Up @@ -335,7 +335,7 @@ impl<'a, W: std::io::Write> OstreeTarWriter<'a, W> {
header.set_size(0);
header.set_uid(meta.uid as u64);
header.set_gid(meta.gid as u64);
header.set_mode(meta.mode);
header.set_mode(meta.mode & !libc::S_IFMT);
self.out
.append_data(&mut header, dirpath, std::io::empty())?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion lib/src/tar/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl Importer {
Some(checksum),
uid,
gid,
mode,
libc::S_IFREG | mode,
xattrs.as_ref(),
&buf,
cancellable,
Expand Down
12 changes: 2 additions & 10 deletions lib/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,7 @@ fn validate_tar_expected<T: std::io::Read>(
let entry_path = entry.path().unwrap().to_string_lossy().into_owned();
if let Some(exp) = expected.remove(entry_path.as_str()) {
assert_eq!(header.entry_type(), exp.etype, "{}", entry_path);
// FIXME: change the generation code to not inject the format bits into the mode,
// because tar doesn't need/use it.
// https://github.com/ostreedev/ostree-rs-ext/pull/217/files#r791942496
assert_eq!(
header.mode().unwrap() & !libc::S_IFMT,
exp.mode,
"{}",
entry_path
);
assert_eq!(header.mode().unwrap(), exp.mode, "{}", entry_path);
}
}

Expand All @@ -303,7 +295,7 @@ fn test_tar_export_structure() -> Result<()> {
let first = entries.next().unwrap()?;
let firstpath = first.path()?;
assert_eq!(firstpath.to_str().unwrap(), "./");
assert_eq!(first.header().mode()?, libc::S_IFDIR | 0o755);
assert_eq!(first.header().mode()?, 0o755);
let next = entries.next().unwrap().unwrap();
assert_eq!(next.path().unwrap().as_os_str(), "sysroot");

Expand Down

0 comments on commit e8282c6

Please sign in to comment.