summaryrefslogtreecommitdiff
path: root/unpack/restore_fstree.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-05-05 01:03:16 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-05-05 01:56:50 +0200
commit949d1c2a5553b54fe6bc2b8c7aca10a892e595d7 (patch)
tree19f23bd62f8099a088926e45216546e813bec80f /unpack/restore_fstree.c
parentda5656a8a696863e0d9941091c09c75b03a6070b (diff)
rdsquashfs: reorder unpack flags, add flag to produce listing
The listing command has been used successfully to do the following: - generate a prestine file system using gensquashfs - repeate multiple times: - generate a listing from the file system - unpack only the regular files from the file system - generate a new file system from the listing - run `diff` on the old and new filesystem and admire that they are identical - replace the old file system with the new one, since they are identical Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'unpack/restore_fstree.c')
-rw-r--r--unpack/restore_fstree.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/unpack/restore_fstree.c b/unpack/restore_fstree.c
index c1320ea..3e7f500 100644
--- a/unpack/restore_fstree.c
+++ b/unpack/restore_fstree.c
@@ -117,27 +117,32 @@ int restore_fstree(const char *rootdir, tree_node_t *root, unsqfs_info_t *info)
if (mkdir_p(rootdir))
return -1;
- dirfd = open(rootdir, O_RDONLY | O_DIRECTORY);
- if (dirfd < 0) {
- perror(rootdir);
- return -1;
+ if (rootdir == NULL) {
+ dirfd = AT_FDCWD;
+ } else {
+ dirfd = open(rootdir, O_RDONLY | O_DIRECTORY);
+ if (dirfd < 0) {
+ perror(rootdir);
+ return -1;
+ }
}
if (S_ISDIR(root->mode)) {
for (n = root->data.dir->children; n != NULL; n = n->next) {
- if (create_node(dirfd, n, info)) {
- close(dirfd);
- return -1;
- }
+ if (create_node(dirfd, n, info))
+ goto fail;
}
return 0;
}
- if (create_node(dirfd, root, info)) {
- close(dirfd);
- return -1;
- }
+ if (create_node(dirfd, root, info))
+ goto fail;
- close(dirfd);
+ if (dirfd != AT_FDCWD)
+ close(dirfd);
return 0;
+fail:
+ if (dirfd != AT_FDCWD)
+ close(dirfd);
+ return -1;
}