Skip to content
Permalink
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
lamby authored and lynxis committed May 25, 2017
1 parent f4324df commit 0ab12a8
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion squashfs-tools/mksquashfs.c
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -5641,6 +5647,36 @@ int main(int argc, char *argv[])
}
}

/* 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
Expand Down Expand Up @@ -5975,7 +6011,7 @@ int main(int argc, char *argv[])
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();

Expand Down

0 comments on commit 0ab12a8

Please sign in to comment.