diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-08-21 14:27:19 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-08-21 15:22:01 +0200 |
commit | 1c8e61f284ff04e3b63c46044d7b890a7e93e302 (patch) | |
tree | 43ec4c898f70e456095a1de5eb3bd358e44c9bfe /difftool/sqfsdiff.c | |
parent | 4ff2b4f689f4e530b6c6f3eed17a595f7ccf56fb (diff) |
Make unified dir to sqfs comparison work
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'difftool/sqfsdiff.c')
-rw-r--r-- | difftool/sqfsdiff.c | 74 |
1 files changed, 66 insertions, 8 deletions
diff --git a/difftool/sqfsdiff.c b/difftool/sqfsdiff.c index 2bc733b..601ffba 100644 --- a/difftool/sqfsdiff.c +++ b/difftool/sqfsdiff.c @@ -19,12 +19,60 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - if (sqfs_reader_open(&sd.sqfs_old, sd.old_path, 0)) - return 2; + /* open first source */ + sd.old_fd = open(sd.old_path, O_DIRECTORY | O_PATH | O_RDONLY); + if (sd.old_fd < 0) { + if (errno == ENOTDIR) { + sd.old_is_dir = false; - if (sqfs_reader_open(&sd.sqfs_new, sd.new_path, 0)) { - status = 2; - goto out_sqfs_old; + if (sqfs_reader_open(&sd.sqfs_old, sd.old_path, 0)) + return 2; + } else { + perror(sd.old_path); + return 2; + } + } else { + sd.old_is_dir = true; + if (fstree_init(&sd.sqfs_old.fs, 512, NULL)) + return 2; + + if (fstree_from_dir(&sd.sqfs_old.fs, sd.old_path, 0)) { + fstree_cleanup(&sd.sqfs_old.fs); + return 2; + } + + tree_node_sort_recursive(sd.sqfs_old.fs.root); + } + + /* open second source */ + sd.new_fd = open(sd.new_path, O_DIRECTORY | O_PATH | O_RDONLY); + if (sd.new_fd < 0) { + if (errno == ENOTDIR) { + sd.new_is_dir = false; + + if (sqfs_reader_open(&sd.sqfs_new, sd.new_path, 0)) { + status = 2; + goto out_sqfs_old; + } + } else { + status = 2; + perror(sd.new_path); + goto out_sqfs_old; + } + } else { + sd.new_is_dir = true; + if (fstree_init(&sd.sqfs_new.fs, 512, NULL)) { + status = 2; + goto out_sqfs_old; + } + + if (fstree_from_dir(&sd.sqfs_new.fs, sd.new_path, 0)) { + status = 2; + fstree_cleanup(&sd.sqfs_old.fs); + goto out_sqfs_old; + } + + tree_node_sort_recursive(sd.sqfs_new.fs.root); } if (sd.extract_dir != NULL) { @@ -39,7 +87,7 @@ int main(int argc, char **argv) if (ret != 0) goto out; - if (sd.compare_super) { + if (sd.compare_super && !sd.old_is_dir && !sd.new_is_dir) { ret = compare_super_blocks(&sd.sqfs_old.super, &sd.sqfs_new.super); if (ret != 0) @@ -53,8 +101,18 @@ out: } else { status = 0; } - sqfs_reader_close(&sd.sqfs_new); + if (sd.new_is_dir) { + close(sd.new_fd); + fstree_cleanup(&sd.sqfs_new.fs); + } else { + sqfs_reader_close(&sd.sqfs_new); + } out_sqfs_old: - sqfs_reader_close(&sd.sqfs_old); + if (sd.old_is_dir) { + close(sd.old_fd); + fstree_cleanup(&sd.sqfs_old.fs); + } else { + sqfs_reader_close(&sd.sqfs_old); + } return status; } |