Skip to content
Permalink
Browse files Browse the repository at this point in the history
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/
  • Loading branch information
intrigeri authored and lynxis committed May 25, 2017
1 parent 0ab12a8 commit 32a07d4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions 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;

/* clamp all timestamps to SOURCE_DATE_EPOCH */
time_t content_clamp_time = -1;

/* override filesystem creation time */
time_t mkfs_fixed_time = -1;

Expand Down Expand Up @@ -2246,6 +2249,8 @@ void reader_read_file(struct dir_ent *dir_ent)
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);
Expand Down Expand Up @@ -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);
Expand All @@ -3110,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);
}

Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -5674,7 +5683,7 @@ int main(int argc, char *argv[])
"%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;
}

/*
Expand Down

0 comments on commit 32a07d4

Please sign in to comment.