summaryrefslogtreecommitdiff
path: root/Source/cmArchiveWrite.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-01-14 13:22:29 -0500
committerBrad King <brad.king@kitware.com>2015-01-19 14:16:19 -0500
commit3a60c899fce77f221cba670b62c90fe2d2daffed (patch)
tree7d7db3b6820f0766b5ecbdcb411b5d5b07ba6ed7 /Source/cmArchiveWrite.cxx
parent90f9c42732a18e53943c3aa27de76c2511c5a0c6 (diff)
downloadcmake-3a60c899fce77f221cba670b62c90fe2d2daffed.tar.gz
cmake: Teach "-E tar" command a "--mtime=" option
Add an option to set the mtime of entries in a tarball so that one can create a tarball with a consistent content hash (e.g. MD5) for a given set of files regardless of their current timestamps on disk. This will be useful for submission of tarballs to CDash, which tracks content hashes to avoid duplication. Inspired-by: Bill Hoffman <bill.hoffman@kitware.com>
Diffstat (limited to 'Source/cmArchiveWrite.cxx')
-rw-r--r--Source/cmArchiveWrite.cxx15
1 files changed, 15 insertions, 0 deletions
diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx
index 16f67f49db..c24c68e4de 100644
--- a/Source/cmArchiveWrite.cxx
+++ b/Source/cmArchiveWrite.cxx
@@ -16,6 +16,7 @@
#include <cmsys/Directory.hxx>
#include <cmsys/FStream.hxx>
#include <cm_libarchive.h>
+#include "cm_get_date.h"
//----------------------------------------------------------------------------
static std::string cm_archive_error_string(struct archive* a)
@@ -277,6 +278,20 @@ bool cmArchiveWrite::AddFile(const char* file,
this->Error += cm_archive_error_string(this->Disk);
return false;
}
+ if (!this->MTime.empty())
+ {
+ time_t now;
+ time(&now);
+ time_t t = cm_get_date(now, this->MTime.c_str());
+ if (t == -1)
+ {
+ this->Error = "unable to parse mtime '";
+ this->Error += this->MTime;
+ this->Error += "'";
+ return false;
+ }
+ archive_entry_set_mtime(e, t, 0);
+ }
// Clear acl and xattr fields not useful for distribution.
archive_entry_acl_clear(e);
archive_entry_xattr_clear(e);