From 687e44297071c95004d47e389fc409b951a8f9ff Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Mon, 27 Apr 2020 20:19:46 +0200 Subject: Cleanup/fix: gensquashfs: split directory scanning from xattr scanning On the one hand, this commit cleanes the code a bit by splitting the "scan directory contents" code from the "scan xattrs from directory contents" and moving the later in a seperate file. On the other hand, the xattr scanning is now done *after* the fstree is post processed, which includes sorting it. This way, the xattrs are always added in a deterministic, reproducible order. Signed-off-by: David Oberhollenzer --- bin/gensquashfs/mkfs.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'bin/gensquashfs/mkfs.c') diff --git a/bin/gensquashfs/mkfs.c b/bin/gensquashfs/mkfs.c index b1542d1..87778d9 100644 --- a/bin/gensquashfs/mkfs.c +++ b/bin/gensquashfs/mkfs.c @@ -150,11 +150,6 @@ static int read_fstree(fstree_t *fs, options_t *opt, sqfs_xattr_writer_t *xwr, FILE *fp; int ret; - if (opt->infile == NULL) { - return fstree_from_dir(fs, opt->packdir, selinux_handle, - xwr, opt->dirscan_flags); - } - fp = fopen(opt->infile, "rb"); if (fp == NULL) { perror(opt->infile); @@ -203,23 +198,27 @@ int main(int argc, char **argv) goto out; } - if (read_fstree(&sqfs.fs, &opt, sqfs.xwr, sehnd)) { - if (sehnd != NULL) - selinux_close_context_file(sehnd); - goto out; + if (opt.infile == NULL) { + if (fstree_from_dir(&sqfs.fs, opt.packdir, opt.dirscan_flags)) + goto out; + } else { + if (read_fstree(&sqfs.fs, &opt, sqfs.xwr, sehnd)) + goto out; } if (opt.force_uid || opt.force_gid) override_owner_dfs(&opt, sqfs.fs.root); - if (sehnd != NULL) { - selinux_close_context_file(sehnd); - sehnd = NULL; - } - if (fstree_post_process(&sqfs.fs)) goto out; + if (opt.infile == NULL) { + if (xattrs_from_dir(&sqfs.fs, opt.packdir, sehnd, + sqfs.xwr, opt.dirscan_flags)) { + goto out; + } + } + if (pack_files(sqfs.data, &sqfs.fs, &opt)) goto out; @@ -229,5 +228,7 @@ int main(int argc, char **argv) status = EXIT_SUCCESS; out: sqfs_writer_cleanup(&sqfs, status); + if (sehnd != NULL) + selinux_close_context_file(sehnd); return status; } -- cgit v1.2.3