Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 10 additions & 6 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ pub enum HeaderMode {

/// Only metadata that is directly relevant to the identity of a file will
/// be included. In particular, ownership and mod/access times are excluded.
Deterministic,
Deterministic {
///If the `mtime` param is `Some(..)`, the value will be used instead of
/// [DETERMINISTIC_TIMESTAMP]
mtime: Option<u64>,
},
}

/// Representation of the header of an entry in an archive
Expand Down Expand Up @@ -777,12 +781,12 @@ impl Header {
self.set_gid(meta.gid() as u64);
self.set_mode(meta.mode());
}
HeaderMode::Deterministic => {
// We could in theory set the mtime to zero here, but not all tools seem to behave
HeaderMode::Deterministic { mtime } => {
// We could in theory default the mtime to zero here, but not all tools seem to behave
// well when ingesting files with a 0 timestamp.
// For example, rust-lang/cargo#9512 shows that lldb doesn't ingest files with a
// zero timestamp correctly.
self.set_mtime(DETERMINISTIC_TIMESTAMP);
self.set_mtime(mtime.unwrap_or(DETERMINISTIC_TIMESTAMP));

self.set_uid(0);
self.set_gid(0);
Expand Down Expand Up @@ -847,10 +851,10 @@ impl Header {
};
self.set_mode(fs_mode);
}
HeaderMode::Deterministic => {
HeaderMode::Deterministic { mtime } => {
self.set_uid(0);
self.set_gid(0);
self.set_mtime(DETERMINISTIC_TIMESTAMP); // see above in unix
self.set_mtime(mtime.unwrap_or(DETERMINISTIC_TIMESTAMP)); // see above in unix
let fs_mode = if meta.is_dir() { 0o755 } else { 0o644 };
self.set_mode(fs_mode);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ fn zero_file_times() {
let td = TempBuilder::new().prefix("tar-rs").tempdir().unwrap();

let mut ar = Builder::new(Vec::new());
ar.mode(HeaderMode::Deterministic);
ar.mode(HeaderMode::Deterministic { mtime: None });
let path = td.path().join("tmpfile");
File::create(&path).unwrap();
ar.append_path_with_name(&path, "a").unwrap();
Expand Down
5 changes: 4 additions & 1 deletion tests/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ fn set_metadata_deterministic() {
perms.set_readonly(readonly);
fs::set_permissions(path, perms).unwrap();
let mut h = Header::new_ustar();
h.set_metadata_in_mode(&path.metadata().unwrap(), HeaderMode::Deterministic);
h.set_metadata_in_mode(
&path.metadata().unwrap(),
HeaderMode::Deterministic { mtime: None },
);
Ok(h)
}

Expand Down