summaryrefslogtreecommitdiff
path: root/unpack/restore_fstree.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-19 15:43:15 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-19 15:58:39 +0200
commit076c1cdb95c12e2b5bf8de33c9d53d93f35ae1c6 (patch)
tree817c3d4c1a3f1bdee88d5f5831a79cf8d5c1049b /unpack/restore_fstree.c
parent4943dd85a9190f4477bd5e98a83be1f5e2790d8d (diff)
Add rdsquashfs flag to restore file timestamps
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'unpack/restore_fstree.c')
-rw-r--r--unpack/restore_fstree.c51
1 files changed, 33 insertions, 18 deletions
diff --git a/unpack/restore_fstree.c b/unpack/restore_fstree.c
index 5681e0a..2ee4c08 100644
--- a/unpack/restore_fstree.c
+++ b/unpack/restore_fstree.c
@@ -109,23 +109,6 @@ static int set_attribs(fstree_t *fs, tree_node_t *n, int flags)
return -1;
}
- if (flags & UNPACK_CHOWN) {
- if (fchownat(AT_FDCWD, n->name, n->uid, n->gid,
- AT_SYMLINK_NOFOLLOW)) {
- fprintf(stderr, "chown %s: %s\n",
- n->name, strerror(errno));
- return -1;
- }
- }
-
- if (flags & UNPACK_CHMOD) {
- if (fchmodat(AT_FDCWD, n->name, n->mode,
- AT_SYMLINK_NOFOLLOW)) {
- fprintf(stderr, "chmod %s: %s\n",
- n->name, strerror(errno));
- return -1;
- }
- }
#ifdef HAVE_SYS_XATTR_H
if ((flags & UNPACK_SET_XATTR) && n->xattr != NULL) {
size_t i, len, kidx, vidx;
@@ -150,6 +133,38 @@ static int set_attribs(fstree_t *fs, tree_node_t *n, int flags)
#else
(void)fs;
#endif
+
+ if (flags & UNPACK_SET_TIMES) {
+ struct timespec times[2];
+
+ memset(times, 0, sizeof(times));
+ times[0].tv_sec = n->mod_time;
+ times[1].tv_sec = n->mod_time;
+
+ if (utimensat(AT_FDCWD, n->name, times, AT_SYMLINK_NOFOLLOW)) {
+ fprintf(stderr, "setting timestamp on %s: %s\n",
+ n->name, strerror(errno));
+ return -1;
+ }
+ }
+
+ if (flags & UNPACK_CHOWN) {
+ if (fchownat(AT_FDCWD, n->name, n->uid, n->gid,
+ AT_SYMLINK_NOFOLLOW)) {
+ fprintf(stderr, "chown %s: %s\n",
+ n->name, strerror(errno));
+ return -1;
+ }
+ }
+
+ if (flags & UNPACK_CHMOD) {
+ if (fchmodat(AT_FDCWD, n->name, n->mode,
+ AT_SYMLINK_NOFOLLOW)) {
+ fprintf(stderr, "chmod %s: %s\n",
+ n->name, strerror(errno));
+ return -1;
+ }
+ }
return 0;
}
@@ -177,7 +192,7 @@ int restore_fstree(tree_node_t *root, int flags)
int update_tree_attribs(fstree_t *fs, tree_node_t *root, int flags)
{
- if ((flags & (UNPACK_CHOWN | UNPACK_CHMOD)) == 0)
+ if ((flags & (UNPACK_CHOWN | UNPACK_CHMOD | UNPACK_SET_TIMES)) == 0)
return 0;
return set_attribs(fs, root, flags);