You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
qubes-installer-qubes-os/squashfs-tools/If-SOURCE_DATE_EPOCH-is-set...

91 lines
2.9 KiB

From 0ab12a8585373be2de5129e14d979c62e7a90d82 Mon Sep 17 00:00:00 2001
From: Chris Lamb <lamby@debian.org>
Date: Mon, 21 Nov 2016 09:33:05 +0100
Subject: [PATCH] If SOURCE_DATE_EPOCH is set, override timestamps with that
value.
See https://reproducible-builds.org/specs/source-date-epoch/ for more
information about this environment variable.
Based on a patch by Alexander Couzens <lynxis@fe...> posted on
https://sourceforge.net/p/squashfs/mailman/message/34673610/
Signed-off-by: Chris Lamb <lamby@debian.org>
---
squashfs-tools/mksquashfs.c | 38 ++++++++++++++++++++++++++++++++++++-
1 file changed, 37 insertions(+), 1 deletion(-)
diff --git a/squashfs-tools/mksquashfs.c b/squashfs-tools/mksquashfs.c
index c2098bd..b49e956 100644
--- a/squashfs-tools/mksquashfs.c
+++ b/squashfs-tools/mksquashfs.c
@@ -137,6 +137,9 @@ unsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;
/* inode lookup table */
squashfs_inode *inode_lookup_table = NULL;
+/* override filesystem creation time */
+time_t mkfs_fixed_time = -1;
+
/* in memory directory data */
#define I_COUNT_SIZE 128
#define DIR_ENTRIES 32
@@ -5104,6 +5107,9 @@ int main(int argc, char *argv[])
int total_mem = get_default_phys_mem();
int progress = TRUE;
int force_progress = FALSE;
+ char *source_date_epoch, *endptr;
+ unsigned long long epoch;
+
struct file_buffer **fragment = NULL;
if(argc > 1 && strcmp(argv[1], "-version") == 0) {
@@ -5641,6 +5647,36 @@ printOptions:
}
}
+ /* if SOURCE_DATE_EPOCH is set, use that timestamp for the mkfs time */
+ source_date_epoch = getenv("SOURCE_DATE_EPOCH");
+ if(source_date_epoch) {
+ errno = 0;
+ epoch = strtoull(source_date_epoch, &endptr, 10);
+ if((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0))
+ || (errno != 0 && epoch == 0)) {
+ ERROR("Environment variable $SOURCE_DATE_EPOCH: "
+ "strtoull: %s\n", strerror(errno));
+ EXIT_MKSQUASHFS();
+ }
+ if(endptr == source_date_epoch) {
+ ERROR("Environment variable $SOURCE_DATE_EPOCH: "
+ "No digits were found: %s\n", endptr);
+ EXIT_MKSQUASHFS();
+ }
+ if(*endptr != '\0') {
+ ERROR("Environment variable $SOURCE_DATE_EPOCH: "
+ "Trailing garbage: %s\n", endptr);
+ EXIT_MKSQUASHFS();
+ }
+ if(epoch > ULONG_MAX) {
+ ERROR("Environment variable $SOURCE_DATE_EPOCH: "
+ "value must be smaller than or equal to "
+ "%lu but was found to be: %llu \n", ULONG_MAX, epoch);
+ EXIT_MKSQUASHFS();
+ }
+ mkfs_fixed_time = (time_t)epoch;
+ }
+
/*
* Some compressors may need the options to be checked for validity
* once all the options have been processed
@@ -5975,7 +6011,7 @@ printOptions:
sBlk.flags = SQUASHFS_MKFLAGS(noI, noD, noF, noX, no_fragments,
always_use_fragments, duplicate_checking, exportable,
no_xattrs, comp_opts);
- sBlk.mkfs_time = time(NULL);
+ sBlk.mkfs_time = mkfs_fixed_time != -1 ? mkfs_fixed_time : time(NULL);
disable_info();
--
2.17.1