From 3e1d98c10523a85b9ccd5038c4ed51ef0ec9d70b Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 18 Jan 2021 14:15:55 +0100 Subject: [PATCH] multify: Respect SOURCE_DATE_EPOCH variable when used from command-line That said, we should probably encourage the use of -T0 (which doesn't write out timestamps to begin with). --- panda/src/downloadertools/multify.cxx | 18 ++++++++++++++++++ panda/src/express/multifile.I | 11 +++++++++++ panda/src/express/multifile.h | 1 + 3 files changed, 30 insertions(+) diff --git a/panda/src/downloadertools/multify.cxx b/panda/src/downloadertools/multify.cxx index bea4c5bedd..d649992b40 100644 --- a/panda/src/downloadertools/multify.cxx +++ b/panda/src/downloadertools/multify.cxx @@ -57,6 +57,7 @@ string dont_compress_str = "jpg,png,mp3,ogg"; // Default text extensions. May be overridden with -X. string text_ext_str = "txt"; +time_t source_date_epoch = (time_t)-1; bool got_record_timestamp_flag = false; bool record_timestamp_flag = true; @@ -430,6 +431,12 @@ add_files(const vector_string ¶ms) { needs_repack = true; } + if (multifile->get_record_timestamp() && source_date_epoch != (time_t)-1) { + if (multifile->get_timestamp() > source_date_epoch) { + multifile->set_timestamp(source_date_epoch); + } + } + if (needs_repack) { if (!multifile->repack()) { cerr << "Failed to write " << multifile_name << ".\n"; @@ -533,6 +540,12 @@ kill_files(const vector_string ¶ms) { } } + if (multifile->get_record_timestamp() && source_date_epoch != (time_t)-1) { + if (multifile->get_timestamp() > source_date_epoch) { + multifile->set_timestamp(source_date_epoch); + } + } + bool okflag = true; if (multifile->needs_repack()) { @@ -779,6 +792,11 @@ main(int argc, char **argv) { } } + const char *source_date_epoch_str = getenv("SOURCE_DATE_EPOCH"); + if (source_date_epoch_str != nullptr && source_date_epoch_str[0] != 0) { + source_date_epoch = (time_t)strtoll(source_date_epoch_str, nullptr, 10); + } + extern char *optarg; extern int optind; static const char *optflags = "crutxkvz123456789Z:T:X:S:f:OC:ep:P:F:h"; diff --git a/panda/src/express/multifile.I b/panda/src/express/multifile.I index 128eb5297e..21462cc467 100644 --- a/panda/src/express/multifile.I +++ b/panda/src/express/multifile.I @@ -67,6 +67,17 @@ get_timestamp() const { return _timestamp; } +/** + * Changes the overall mudification timestamp of the multifile. Note that this + * will be reset to the current time every time you modify a subfile. + * Only set this if you know what you are doing! + */ +INLINE void Multifile:: +set_timestamp(time_t timestamp) { + _timestamp = timestamp; + _timestamp_dirty = true; +} + /** * Sets the flag indicating whether timestamps should be recorded within the * Multifile or not. The default is true, indicating the Multifile will diff --git a/panda/src/express/multifile.h b/panda/src/express/multifile.h index 540bf434d2..99b5242127 100644 --- a/panda/src/express/multifile.h +++ b/panda/src/express/multifile.h @@ -59,6 +59,7 @@ PUBLISHED: INLINE bool needs_repack() const; INLINE time_t get_timestamp() const; + INLINE void set_timestamp(time_t timestamp); INLINE void set_record_timestamp(bool record_timestamp); INLINE bool get_record_timestamp() const;