From db8bb73cd9ded427ab346b557b3c97ba425400d0 Mon Sep 17 00:00:00 2001 From: "Vladimir D. Seleznev" Date: Tue, 14 Nov 2017 22:01:15 +0300 Subject: [PATCH 1/2] Add support for SOURCE_DATE_EPOCH environment variable This allows rpmbuild to override file timestamps. Based on rpm.org commit 8d84878. --- build/files.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/build/files.c b/build/files.c index fd70c9d..990155f 100644 --- a/build/files.c +++ b/build/files.c @@ -8,6 +8,7 @@ #define MYALLPERMS 07777 +#include #include #include /* getOutputFrom() */ @@ -997,7 +998,27 @@ static void genCpioListAndHeader(Spec spec, /*@partial@*/ FileList fl, FileListRec flp; char buf[BUFSIZ]; int i; - + int override_date = 0; + time_t source_date_epoch; + const char *srcdate = getenv("SOURCE_DATE_EPOCH"); + + /* Limit the maximum date to SOURCE_DATE_EPOCH if defined + * similar to the tar --clamp-mtime option + * https://reproducible-builds.org/specs/source-date-epoch/ + */ + if (srcdate && *srcdate) { + char *endptr; + errno = 0; + source_date_epoch = strtol(srcdate, &endptr, 10); + if (srcdate == endptr || *endptr + || ((source_date_epoch == LONG_MIN || source_date_epoch == LONG_MAX) + && errno != 0)) { + rpmlog(RPMLOG_ERR, _("unable to parse %s=%s\n"), "SOURCE_DATE_EPOCH", srcdate); + } else { + override_date = 1; + } + } + /* Sort the big list */ qsort(fl->fileList, fl->fileListRecsUsed, sizeof(*(fl->fileList)), compareFileListRecs); @@ -1068,6 +1089,10 @@ static void genCpioListAndHeader(Spec spec, /*@partial@*/ FileList fl, continue; } + if (override_date && flp->fl_mtime > source_date_epoch) { + flp->fl_mtime = source_date_epoch; + } + /* Omit '/' and/or URL prefix, leave room for "./" prefix */ apathlen += (strlen(flp->fileURL) - skipLen + (_addDotSlash ? 3 : 1)); -- 2.10.4