summary refs log tree commit diff
path: root/pkgs/tools/filesystems/squashfs/0002-If-SOURCE_DATE_EPOCH-is-set-also-clamp-content-times.patch
blob: 5002375887fb8153044b1a33f9e0b57aee1441e9 (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
From 32a07d4156a281084c90a4b78affc8b0b32a26fc Mon Sep 17 00:00:00 2001
From: intrigeri <intrigeri@boum.org>
Date: Mon, 21 Nov 2016 11:41:28 +0000
Subject: [PATCH] If SOURCE_DATE_EPOCH is set, also clamp content timestamps
 with that value.

Based on a patch by Alexander Couzens <lynxis@fe...> posted on
https://sourceforge.net/p/squashfs/mailman/message/34673610/
---
 squashfs-tools/mksquashfs.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/squashfs-tools/mksquashfs.c b/squashfs-tools/mksquashfs.c
index b49e956..9f020bf 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;
 
+/* clamp all timestamps to SOURCE_DATE_EPOCH */
+time_t content_clamp_time = -1;
+
 /* override filesystem creation time */
 time_t mkfs_fixed_time = -1;
 
@@ -2246,6 +2249,8 @@ restat:
 			  pathname_reader(dir_ent), strerror(errno));
 		goto read_err;
 	}
+	if(content_clamp_time != -1 && buf2.st_mtime >= content_clamp_time)
+		buf2.st_mtime = content_clamp_time;
 
 	if(read_size != buf2.st_size) {
 		close(file);
@@ -3101,7 +3106,7 @@ void dir_scan(squashfs_inode *inode, char *pathname,
 		buf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR;
 		buf.st_uid = getuid();
 		buf.st_gid = getgid();
-		buf.st_mtime = time(NULL);
+		buf.st_mtime = content_clamp_time != -1 ? content_clamp_time : time(NULL);
 		buf.st_dev = 0;
 		buf.st_ino = 0;
 		dir_ent->inode = lookup_inode2(&buf, PSEUDO_FILE_OTHER, 0);
@@ -3127,6 +3115,8 @@ void dir_scan(squashfs_inode *inode, char *pathname,
			/* source directory has disappeared? */
			BAD_ERROR("Cannot stat source directory %s because %s\n",
				pathname, strerror(errno));
+		if(content_clamp_time != -1 && buf.st_mtime >= content_clamp_time)
+			buf.st_mtime = content_clamp_time;
 		dir_ent->inode = lookup_inode(&buf);
 	}
 
@@ -3365,6 +3372,8 @@ struct dir_info *dir_scan1(char *filename, char *subpath,
 			free_dir_entry(dir_ent);
 			continue;
 		}
+		if(content_clamp_time != -1 && buf.st_mtime >= content_clamp_time)
+			buf.st_mtime = content_clamp_time;
 
 		if((buf.st_mode & S_IFMT) != S_IFREG &&
 				(buf.st_mode & S_IFMT) != S_IFDIR &&
@@ -3544,7 +3553,7 @@ void dir_scan2(struct dir_info *dir, struct pseudo *pseudo)
		buf.st_gid = pseudo_ent->dev->gid;
		buf.st_rdev = makedev(pseudo_ent->dev->major,
			pseudo_ent->dev->minor);
-		buf.st_mtime = time(NULL);
+		buf.st_mtime = content_clamp_time != -1 ? content_clamp_time : time(NULL);
 		buf.st_ino = pseudo_ino ++;
 
 		if(pseudo_ent->dev->type == 'd') {
@@ -5674,7 +5683,7 @@ printOptions:
 				"%lu but was found to be: %llu \n", ULONG_MAX, epoch);
 			EXIT_MKSQUASHFS();
 		}
-		mkfs_fixed_time = (time_t)epoch;
+		mkfs_fixed_time = content_clamp_time = (time_t)epoch;
 	}
 
 	/*
-- 
2.17.0