Skip to content

Commit e8282c6

Browse files
authored
Merge pull request ostreedev#220 from lucab/ups/tar-mode-mask
tar/export: fix mode bits in tar archive
2 parents 8274bd0 + cde864b commit e8282c6

File tree

3 files changed

+5
-13
lines changed

3 files changed

+5
-13
lines changed

lib/src/tar/export.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ impl<'a, W: std::io::Write> OstreeTarWriter<'a, W> {
281281
h.set_uid(meta.attribute_uint32("unix::uid") as u64);
282282
h.set_gid(meta.attribute_uint32("unix::gid") as u64);
283283
let mode = meta.attribute_uint32("unix::mode");
284-
h.set_mode(mode);
284+
h.set_mode(mode & !libc::S_IFMT);
285285
let mut target_header = h.clone();
286286
target_header.set_size(0);
287287

@@ -335,7 +335,7 @@ impl<'a, W: std::io::Write> OstreeTarWriter<'a, W> {
335335
header.set_size(0);
336336
header.set_uid(meta.uid as u64);
337337
header.set_gid(meta.gid as u64);
338-
header.set_mode(meta.mode);
338+
header.set_mode(meta.mode & !libc::S_IFMT);
339339
self.out
340340
.append_data(&mut header, dirpath, std::io::empty())?;
341341
Ok(())

lib/src/tar/import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl Importer {
266266
Some(checksum),
267267
uid,
268268
gid,
269-
mode,
269+
libc::S_IFREG | mode,
270270
xattrs.as_ref(),
271271
&buf,
272272
cancellable,

lib/tests/it/main.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,7 @@ fn validate_tar_expected<T: std::io::Read>(
269269
let entry_path = entry.path().unwrap().to_string_lossy().into_owned();
270270
if let Some(exp) = expected.remove(entry_path.as_str()) {
271271
assert_eq!(header.entry_type(), exp.etype, "{}", entry_path);
272-
// FIXME: change the generation code to not inject the format bits into the mode,
273-
// because tar doesn't need/use it.
274-
// https://github.com/ostreedev/ostree-rs-ext/pull/217/files#r791942496
275-
assert_eq!(
276-
header.mode().unwrap() & !libc::S_IFMT,
277-
exp.mode,
278-
"{}",
279-
entry_path
280-
);
272+
assert_eq!(header.mode().unwrap(), exp.mode, "{}", entry_path);
281273
}
282274
}
283275

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

0 commit comments

Comments
 (0)