aboutsummaryrefslogtreecommitdiffstats
path: root/tools/mtd-utils/patches/320-mkfs.jffs2-SOURCE_DATE_EPOCH.patch
blob: 46014e7a323a454e2e77a5bfd6885f38b157a072 (plain)
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
Index: mtd-utils-1.5.2/mkfs.jffs2.c
===================================================================
--- mtd-utils-1.5.2.orig/mkfs.jffs2.c
+++ mtd-utils-1.5.2/mkfs.jffs2.c
@@ -108,7 +108,7 @@ static char *rootdir = default_rootdir;
 static int verbose = 0;
 static int squash_uids = 0;
 static int squash_perms = 0;
-static int fake_times = 0;
+static time_t fixed_timestamp = -1;
 int target_endian = __BYTE_ORDER;
 
 uint32_t find_hardlink(struct filesystem_entry *e)
@@ -249,8 +249,8 @@ static struct filesystem_entry *add_host
 			mode &= ~(S_ISUID | S_ISGID);
 		}
 	}
-	if (fake_times) {
-		timestamp = 0;
+	if (fixed_timestamp != -1) {
+		timestamp = fixed_timestamp;
 	}
 
 	entry = xcalloc(1, sizeof(struct filesystem_entry));
@@ -1554,6 +1554,20 @@ void parse_image(){
 	close(in_fd);
 }
 
+static void set_source_date_epoch() {
+	char *env = getenv("SOURCE_DATE_EPOCH");
+	char *endptr = env;
+	errno = 0;
+	if (env && *env) {
+		fixed_timestamp = strtoull(env, &endptr, 10);
+		if (errno || (endptr && *endptr != '\0')) {
+			fprintf(stderr, "Invalid SOURCE_DATE_EPOCH");
+			exit(1);
+		}
+	}
+}
+
+
 int main(int argc, char **argv)
 {
 	int c, opt;
@@ -1572,6 +1586,7 @@ int main(int argc, char **argv)
 		warn_page_size = 1; /* warn user if page size not 4096 */
 
 	jffs2_compressors_init();
+	set_source_date_epoch();
 
 	while ((opt = getopt_long(argc, argv,
 					"D:d:r:s:o:qUPfh?vVe:lbp::nc:m:x:X:Lty:i:", long_options, &c)) >= 0)
@@ -1622,7 +1637,7 @@ int main(int argc, char **argv)
 				break;
 
 			case 'f':
-				fake_times = 1;
+				fixed_timestamp = 0;
 				break;
 
 			case 'h':