nixpkgs/pkgs/tools/filesystems/squashfs/0002-If-SOURCE_DATE_EPOCH-is-set-also-clamp-content-times.patch

84 lines
2.8 KiB
Diff
Raw Normal View History

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