summaryrefslogtreecommitdiff
path: root/tar/tar2sqfs.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-22 03:28:05 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-22 17:12:45 +0200
commitadc8e37d7f86d661ab54adf9c43e4b0aa67a939c (patch)
treed075abb80d7cd22935a32e20e5bfcb53acef087d /tar/tar2sqfs.c
parentc673f305ec0c2c80bc3873bcc8718d9ba85340c9 (diff)
Add a way to optionally keep the original time stamps
First of all, this commit adds a mod_time field to a tree node. When creating the tree node, the field is set from the struct stat. When scanning a directory, the time stamps from the input are used if set. Second, the libsqfs code that reads inodes is modified to store the mod_time from the inode in the fstree node and to write the tree node into a generated inode. Finally, tar2sqfs is modified to optionally keep the timestamps from the tar archive instead of setting defaults. gensquashfs is similarly modified to keep the input timestamps if specified. The result is as follows: - sqfs2tar will always carry the timestamps from the squashfs over to the tar ball. - tar2sqfs will set defaults, unless explicitly asked to preserve the mtime from the tar ball. - gensquashfs can optionally preserve the mtime from the input hierarchy it processes if only --pack-dir is specified. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tar/tar2sqfs.c')
-rw-r--r--tar/tar2sqfs.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/tar/tar2sqfs.c b/tar/tar2sqfs.c
index f557f95..2493c3b 100644
--- a/tar/tar2sqfs.c
+++ b/tar/tar2sqfs.c
@@ -26,6 +26,7 @@ static struct option long_opts[] = {
{ "comp-extra", required_argument, NULL, 'X' },
{ "no-skip", no_argument, NULL, 's' },
{ "no-xattr", no_argument, NULL, 'x' },
+ { "keep-time", no_argument, NULL, 'k' },
{ "exportable", no_argument, NULL, 'e' },
{ "force", no_argument, NULL, 'f' },
{ "quiet", no_argument, NULL, 'q' },
@@ -33,7 +34,7 @@ static struct option long_opts[] = {
{ "version", no_argument, NULL, 'V' },
};
-static const char *short_opts = "c:b:B:d:X:sxefqhV";
+static const char *short_opts = "c:b:B:d:X:sxekfqhV";
static const char *usagestr =
"Usage: tar2sqfs [OPTIONS...] <sqfsfile>\n"
@@ -64,6 +65,8 @@ static const char *usagestr =
" --no-skip, -s Abort if a tar record cannot be read instead\n"
" of skipping it.\n"
" --no-xattr, -x Do not copy extended attributes from archive.\n"
+" --keep-time, -k Keep the time stamps stored in the archive\n"
+" instead of setting defaults on all files.\n"
" --exportable, -e Generate an export table for NFS support.\n"
" --force, -f Overwrite the output file if it exists.\n"
" --quiet, -q Do not print out progress reports.\n"
@@ -88,6 +91,7 @@ static char *fs_defaults = NULL;
static bool dont_skip = false;
static bool no_xattr = false;
static bool exportable = false;
+static bool keep_time = false;
static void process_args(int argc, char **argv)
{
@@ -137,6 +141,9 @@ static void process_args(int argc, char **argv)
case 'x':
no_xattr = true;
break;
+ case 'k':
+ keep_time = true;
+ break;
case 's':
dont_skip = true;
break;
@@ -234,6 +241,12 @@ static int create_node_and_repack_data(tar_header_decoded_t *hdr, fstree_t *fs,
{
tree_node_t *node;
+ if (!keep_time) {
+ hdr->sb.st_mtime = fs->defaults.st_mtime;
+ hdr->sb.st_ctime = fs->defaults.st_ctime;
+ hdr->sb.st_atime = fs->defaults.st_atime;
+ }
+
node = fstree_add_generic(fs, hdr->name, &hdr->sb, hdr->link_target);
if (node == NULL)
goto fail_errno;