summaryrefslogtreecommitdiffstats
path: root/Source/cmArchiveWrite.cxx
diff options
context:
space:
mode:
authorAndrew Fuller <afuller@teradici.com>2018-07-20 01:14:40 (GMT)
committerAndrew Fuller <afuller@teradici.com>2018-07-25 20:39:07 (GMT)
commit548ac51d8ea319c65abefa0a771636893c45014c (patch)
tree90e75a26ef74a701937f24bc03495b684d765fb2 /Source/cmArchiveWrite.cxx
parent8dc86970c86ec53513a17f4cdb28f2a0be3ee505 (diff)
downloadCMake-548ac51d8ea319c65abefa0a771636893c45014c.zip
CMake-548ac51d8ea319c65abefa0a771636893c45014c.tar.gz
CMake-548ac51d8ea319c65abefa0a771636893c45014c.tar.bz2
CPack/Deb: Support SOURCE_DATE_EPOCH when packaging files
Diffstat (limited to 'Source/cmArchiveWrite.cxx')
-rw-r--r--Source/cmArchiveWrite.cxx28
1 files changed, 26 insertions, 2 deletions
diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx
index 1dd7734..6031781 100644
--- a/Source/cmArchiveWrite.cxx
+++ b/Source/cmArchiveWrite.cxx
@@ -10,6 +10,7 @@
#include "cmsys/Encoding.hxx"
#include "cmsys/FStream.hxx"
#include <iostream>
+#include <sstream>
#include <string.h>
#include <time.h>
@@ -94,13 +95,25 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c,
return;
}
break;
- case CompressGZip:
+ case CompressGZip: {
if (archive_write_add_filter_gzip(this->Archive) != ARCHIVE_OK) {
this->Error = "archive_write_add_filter_gzip: ";
this->Error += cm_archive_error_string(this->Archive);
return;
}
- break;
+ std::string source_date_epoch;
+ cmSystemTools::GetEnv("SOURCE_DATE_EPOCH", source_date_epoch);
+ if (!source_date_epoch.empty()) {
+ // We're not able to specify an arbitrary timestamp for gzip.
+ // The next best thing is to omit the timestamp entirely.
+ if (archive_write_set_filter_option(this->Archive, "gzip", "timestamp",
+ nullptr) != ARCHIVE_OK) {
+ this->Error = "archive_write_set_filter_option: ";
+ this->Error += cm_archive_error_string(this->Archive);
+ return;
+ }
+ }
+ } break;
case CompressBZip2:
if (archive_write_add_filter_bzip2(this->Archive) != ARCHIVE_OK) {
this->Error = "archive_write_add_filter_bzip2: ";
@@ -243,6 +256,17 @@ bool cmArchiveWrite::AddFile(const char* file, size_t skip, const char* prefix)
return false;
}
archive_entry_set_mtime(e, t, 0);
+ } else {
+ std::string source_date_epoch;
+ cmSystemTools::GetEnv("SOURCE_DATE_EPOCH", source_date_epoch);
+ if (!source_date_epoch.empty()) {
+ std::istringstream iss(source_date_epoch);
+ time_t epochTime;
+ iss >> epochTime;
+ if (iss.eof() && !iss.fail()) {
+ archive_entry_set_mtime(e, epochTime, 0);
+ }
+ }
}
// manages the uid/guid of the entry (if any)