aboutsummaryrefslogtreecommitdiff
path: root/mkfs
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 /mkfs
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 'mkfs')
-rw-r--r--mkfs/block.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/mkfs/block.c b/mkfs/block.c
index 545df53..de2c962 100644
--- a/mkfs/block.c
+++ b/mkfs/block.c
@@ -211,8 +211,25 @@ static int find_and_process_files(sqfs_info_t *info, tree_node_t *n,
int write_data_to_image(sqfs_info_t *info)
{
+ bool need_restore = false;
+ const char *ptr;
int ret;
+ if (info->opt.packdir != NULL) {
+ if (pushd(info->opt.packdir))
+ return -1;
+ need_restore = true;
+ } else {
+ ptr = strrchr(info->opt.infile, '/');
+
+ if (ptr != NULL) {
+ if (pushdn(info->opt.infile, ptr - info->opt.infile))
+ return -1;
+
+ need_restore = true;
+ }
+ }
+
info->block = malloc(info->super.block_size);
if (info->block == NULL) {
@@ -245,5 +262,9 @@ int write_data_to_image(sqfs_info_t *info)
info->block = NULL;
info->fragment = NULL;
info->scratch = NULL;
+
+ if (need_restore)
+ ret = popd();
+
return ret;
}