summary refs log tree commit diff
path: root/pkgs/tools/filesystems/squashfs/0001-If-SOURCE_DATE_EPOCH-is-set-override-timestamps-with.patch
blob: 5626800e723cb94991d26af01e620ee8f132c08f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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
@@ -5993,7 +6029,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.0