From 3559e5e0e840839ae85aa02c0748f89676c0a5e8 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Fri, 31 May 2019 19:25:16 +0200 Subject: gensquashfs: allow combining packdir and packfile If packdir and packfile are both specified, use packdir as alternate root. Signed-off-by: David Oberhollenzer --- lib/fstree/fstree_from_file.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/fstree/fstree_from_file.c b/lib/fstree/fstree_from_file.c index c2fac7a..5a87222 100644 --- a/lib/fstree/fstree_from_file.c +++ b/lib/fstree/fstree_from_file.c @@ -362,7 +362,7 @@ out_desc: return -1; } -int fstree_from_file(fstree_t *fs, const char *filename) +int fstree_from_file(fstree_t *fs, const char *filename, const char *rootdir) { FILE *fp = fopen(filename, "rb"); size_t n, line_num = 0; @@ -375,23 +375,30 @@ int fstree_from_file(fstree_t *fs, const char *filename) return -1; } - ptr = strrchr(filename, '/'); + if (rootdir == NULL) { + ptr = strrchr(filename, '/'); - if (ptr != NULL) { - line = strndup(filename, ptr - filename); - if (line == NULL) { - perror("composing root path"); - return -1; - } + if (ptr != NULL) { + line = strndup(filename, ptr - filename); + if (line == NULL) { + perror("composing root path"); + return -1; + } + + if (chdir(line)) { + perror(line); + free(line); + return -1; + } - if (chdir(line)) { - perror(line); free(line); + line = NULL; + } + } else { + if (chdir(rootdir)) { + perror(rootdir); return -1; } - - free(line); - line = NULL; } for (;;) { -- cgit v1.2.3