diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-06-10 00:28:55 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-06-10 00:28:55 +0200 |
commit | dfcb5d93c6fb3d5c1c933275622d938e83da6a70 (patch) | |
tree | b82ac96ae5e89d7f00c0547b8117c9101808a14f /mkfs | |
parent | 781716c240da330d57f27bf22f48017f9132a489 (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.c | 21 |
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; } |