Skip to content

Commit

Permalink
Unify mtime constant used on Unix and Windows (#346)
Browse files Browse the repository at this point in the history
* Unify `mtime` constant used on Unix and Windows

fix #341

* Extract `DETERMINISTIC_TIMESTAMP`
  • Loading branch information
mkaput authored Jun 4, 2024
1 parent 3474445 commit dd9123c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ use std::str;
use crate::other;
use crate::EntryType;

/// A deterministic, arbitrary, non-zero timestamp that use used as `mtime`
/// of headers when [`HeaderMode::Deterministic`] is used.
///
/// This value, chosen after careful deliberation, corresponds to _Jul 23, 2006_,
/// which is the date of the first commit for what would become Rust.
#[cfg(any(unix, windows))]
const DETERMINISTIC_TIMESTAMP: u64 = 1153704088;

/// Representation of the header of an entry in an archive
#[repr(C)]
#[allow(missing_docs)]
Expand Down Expand Up @@ -748,16 +756,11 @@ impl Header {
self.set_mode(meta.mode() as u32);
}
HeaderMode::Deterministic => {
// We could in theory set 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.
//
// We just need things to be deterministic here so just pick
// something that isn't zero. This time, chosen after careful
// deliberation, corresponds to Jul 23, 2006 -- the date of the
// first commit for what would become Rust.
self.set_mtime(1153704088);
// We could in theory set 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_uid(0);
self.set_gid(0);
Expand Down Expand Up @@ -825,7 +828,7 @@ impl Header {
HeaderMode::Deterministic => {
self.set_uid(0);
self.set_gid(0);
self.set_mtime(123456789); // see above in unix
self.set_mtime(DETERMINISTIC_TIMESTAMP); // see above in unix
let fs_mode = if meta.is_dir() { 0o755 } else { 0o644 };
self.set_mode(fs_mode);
}
Expand Down
1 change: 1 addition & 0 deletions tests/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ fn set_metadata_deterministic() {

// Would not match without `Deterministic`.
assert_eq!(t!(one.mtime()), t!(two.mtime()));
assert_eq!(t!(one.mtime()), 1153704088);
// TODO: No great way to validate that these would not be filled, but
// check them anyway.
assert_eq!(t!(one.uid()), t!(two.uid()));
Expand Down

0 comments on commit dd9123c

Please sign in to comment.