aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-11 18:15:10 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-11 18:15:10 +0200
commit842c5ec8e5c05e0d9c245882f13ca0a6b19825f5 (patch)
treed04f058efdc486bc25890b8f4d3dea6ea38c5764
parent8fa122a59f61878bafa43ea45d9ea988f3a70998 (diff)
cleanup: pull out common code path
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--unpack/options.c2
-rw-r--r--unpack/rdsquashfs.c20
2 files changed, 8 insertions, 14 deletions
diff --git a/unpack/options.c b/unpack/options.c
index ccfe7c8..84c17cf 100644
--- a/unpack/options.c
+++ b/unpack/options.c
@@ -124,6 +124,8 @@ void process_command_line(options_t *opt, int argc, char **argv)
break;
case 'd':
opt->op = OP_DESCRIBE;
+ free(opt->cmdpath);
+ opt->cmdpath = NULL;
break;
case 'l':
opt->op = OP_LS;
diff --git a/unpack/rdsquashfs.c b/unpack/rdsquashfs.c
index 27a0cf5..125a841 100644
--- a/unpack/rdsquashfs.c
+++ b/unpack/rdsquashfs.c
@@ -85,23 +85,21 @@ int main(int argc, char **argv)
if (deserialize_fstree(&fs, &super, cmp, sqfsfd, opt.rdtree_flags))
goto out_cmp;
- switch (opt.op) {
- case OP_LS:
+ if (opt.cmdpath != NULL) {
n = find_node(fs.root, opt.cmdpath);
if (n == NULL) {
perror(opt.cmdpath);
goto out_fs;
}
+ } else {
+ n = fs.root;
+ }
+ switch (opt.op) {
+ case OP_LS:
list_files(n);
break;
case OP_CAT:
- n = find_node(fs.root, opt.cmdpath);
- if (n == NULL) {
- perror(opt.cmdpath);
- goto out_fs;
- }
-
if (!S_ISREG(n->mode)) {
fprintf(stderr, "/%s: not a regular file\n",
opt.cmdpath);
@@ -116,12 +114,6 @@ int main(int argc, char **argv)
goto out_fs;
break;
case OP_UNPACK:
- n = find_node(fs.root, opt.cmdpath);
- if (n == NULL) {
- perror(opt.cmdpath);
- goto out_fs;
- }
-
data = data_reader_create(sqfsfd, &super, cmp);
if (data == NULL)
goto out_fs;