From b3c3401aee91bc2ff46ba0eab0ceb88c78cb5bbb Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Fri, 9 Aug 2019 11:43:15 +0200 Subject: Add option to sqfsdiff to extract regular files that are different Signed-off-by: David Oberhollenzer --- difftool/sqfsdiff.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'difftool/sqfsdiff.c') diff --git a/difftool/sqfsdiff.c b/difftool/sqfsdiff.c index 8818a37..4754557 100644 --- a/difftool/sqfsdiff.c +++ b/difftool/sqfsdiff.c @@ -13,11 +13,12 @@ static struct option long_opts[] = { { "timestamps", no_argument, NULL, 'T' }, { "inode-num", no_argument, NULL, 'I' }, { "super", no_argument, NULL, 'S' }, + { "extract", required_argument, NULL, 'e' }, { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, }; -static const char *short_opts = "OPCTIShV"; +static const char *short_opts = "OPCTISe:hV"; static const char *usagestr = "Usage: sqfsdiff [OPTIONS...] \n" @@ -45,6 +46,11 @@ static const char *usagestr = " --inode-num, -I Compare inode numbers of all files.\n" " --super, -S Also compare metadata in super blocks.\n" "\n" +" --extract, -e Extract files that differ to the specified\n" +" directory. Contents of the first image end up\n" +" in a subdirectory 'a' and of the second image\n" +" in a subdirectory 'b'.\n" +"\n" " --help, -h Print help text and exit.\n" " --version, -V Print version information and exit.\n" "\n"; @@ -55,6 +61,7 @@ const char *second_path; sqfs_reader_t sqfs_a; sqfs_reader_t sqfs_b; static bool compare_super = false; +static const char *extract_dir; static void process_options(int argc, char **argv) { @@ -84,6 +91,10 @@ static void process_options(int argc, char **argv) case 'S': compare_super = true; break; + case 'e': + compare_flags |= COMPARE_EXTRACT_FILES; + extract_dir = optarg; + break; case 'h': fputs(usagestr, stdout); exit(EXIT_SUCCESS); @@ -125,6 +136,11 @@ int main(int argc, char **argv) process_options(argc, argv); + if (extract_dir != NULL) { + if (mkdir_p(extract_dir)) + return EXIT_FAILURE; + } + if (sqfs_reader_open(&sqfs_a, first_path, 0)) return 2; @@ -133,6 +149,14 @@ int main(int argc, char **argv) goto out_sqfs_a; } + if (extract_dir != NULL) { + if (chdir(extract_dir)) { + perror(extract_dir); + ret = -1; + goto out; + } + } + ret = node_compare(sqfs_a.fs.root, sqfs_b.fs.root); if (ret != 0) goto out; -- cgit v1.2.3