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

Unify mtime constant used on Unix and Windows #346

Merged
merged 2 commits into from
Jun 4, 2024
Merged
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
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