summaryrefslogtreecommitdiff
path: root/lib/fstree
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-10 00:28:55 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-10 00:28:55 +0200
commitdfcb5d93c6fb3d5c1c933275622d938e83da6a70 (patch)
treeb82ac96ae5e89d7f00c0547b8117c9101808a14f /lib/fstree
parent781716c240da330d57f27bf22f48017f9132a489 (diff)
gensquashfs: do pushd/popd when needed instead of chdir
This commit replaces the chdir to the input directory with pushd/popd when building the fstree and again when packing files. This simplifies handling of other file paths given on the command line that have to be accessed and are relative to the original working directories. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/fstree')
-rw-r--r--lib/fstree/fstree_from_file.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/lib/fstree/fstree_from_file.c b/lib/fstree/fstree_from_file.c
index 5a87222..affa769 100644
--- a/lib/fstree/fstree_from_file.c
+++ b/lib/fstree/fstree_from_file.c
@@ -365,6 +365,7 @@ out_desc:
int fstree_from_file(fstree_t *fs, const char *filename, const char *rootdir)
{
FILE *fp = fopen(filename, "rb");
+ bool need_restore = false;
size_t n, line_num = 0;
const char *ptr;
ssize_t ret;
@@ -379,26 +380,16 @@ int fstree_from_file(fstree_t *fs, const char *filename, const char *rootdir)
ptr = strrchr(filename, '/');
if (ptr != NULL) {
- line = strndup(filename, ptr - filename);
- if (line == NULL) {
- perror("composing root path");
- return -1;
- }
-
- if (chdir(line)) {
- perror(line);
+ if (pushdn(filename, ptr - filename)) {
free(line);
return -1;
}
-
- free(line);
- line = NULL;
+ need_restore = true;
}
} else {
- if (chdir(rootdir)) {
- perror(rootdir);
+ if (pushd(rootdir))
return -1;
- }
+ need_restore = true;
}
for (;;) {
@@ -433,6 +424,10 @@ int fstree_from_file(fstree_t *fs, const char *filename, const char *rootdir)
}
fclose(fp);
+
+ if (need_restore && popd() != 0)
+ return -1;
+
return 0;
fail_line:
free(line);