From dfcb5d93c6fb3d5c1c933275622d938e83da6a70 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Mon, 10 Jun 2019 00:28:55 +0200 Subject: 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 --- mkfs/block.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'mkfs') 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; } -- cgit v1.2.3