From 4ff2b4f689f4e530b6c6f3eed17a595f7ccf56fb Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Wed, 21 Aug 2019 14:04:43 +0200 Subject: Isolate sqfsdiff global state and split off option processing Signed-off-by: David Oberhollenzer --- difftool/compare_files.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'difftool/compare_files.c') diff --git a/difftool/compare_files.c b/difftool/compare_files.c index 46e170b..605df84 100644 --- a/difftool/compare_files.c +++ b/difftool/compare_files.c @@ -9,10 +9,11 @@ static unsigned char old_buf[MAX_WINDOW_SIZE]; static unsigned char new_buf[MAX_WINDOW_SIZE]; -int compare_files(file_info_t *old, file_info_t *new, const char *path) +int compare_files(sqfsdiff_t *sd, file_info_t *old, file_info_t *new, + const char *path) { - char new_name[strlen(new_path) + strlen(path) + 2]; - char old_name[strlen(old_path) + strlen(path) + 2]; + char new_name[strlen(sd->new_path) + strlen(path) + 2]; + char old_name[strlen(sd->old_path) + strlen(path) + 2]; int old_fd = -1, new_fd = -1, status = 0; uint64_t offset, diff; ssize_t ret; @@ -20,11 +21,11 @@ int compare_files(file_info_t *old, file_info_t *new, const char *path) if (old->size != new->size) goto out_different; - if (compare_flags & COMPARE_NO_CONTENTS) + if (sd->compare_flags & COMPARE_NO_CONTENTS) return 0; - if (old_is_dir) { - sprintf(old_name, "%s/%s", old_path, path); + if (sd->old_is_dir) { + sprintf(old_name, "%s/%s", sd->old_path, path); old_fd = open(old_name, O_RDONLY); if (old_fd < 0) { @@ -33,8 +34,8 @@ int compare_files(file_info_t *old, file_info_t *new, const char *path) } } - if (new_is_dir) { - sprintf(new_name, "%s/%s", new_path, path); + if (sd->new_is_dir) { + sprintf(new_name, "%s/%s", sd->new_path, path); new_fd = open(new_name, O_RDONLY); if (new_fd < 0) { @@ -49,30 +50,30 @@ int compare_files(file_info_t *old, file_info_t *new, const char *path) if (diff > MAX_WINDOW_SIZE) diff = MAX_WINDOW_SIZE; - if (old_is_dir) { + if (sd->old_is_dir) { if (read_data_at(old_name, offset, old_fd, old_buf, diff)) goto out; } else { - ret = data_reader_read(sqfs_old.data, old, offset, + ret = data_reader_read(sd->sqfs_old.data, old, offset, old_buf, diff); if (ret < 0 || (size_t)ret < diff) { fprintf(stderr, "Failed to read %s from %s\n", - path, old_path); + path, sd->old_path); return -1; } } - if (new_is_dir) { + if (sd->new_is_dir) { if (read_data_at(new_name, offset, new_fd, new_buf, diff)) goto out; } else { - ret = data_reader_read(sqfs_new.data, new, offset, + ret = data_reader_read(sd->sqfs_new.data, new, offset, new_buf, diff); if (ret < 0 || (size_t)ret < diff) { fprintf(stderr, "Failed to read %s from %s\n", - path, new_path); + path, sd->new_path); return -1; } } @@ -90,8 +91,8 @@ fail: status = -1; goto out; out_different: - if (compare_flags & COMPARE_EXTRACT_FILES) { - if (extract_files(old, new, path)) + if (sd->compare_flags & COMPARE_EXTRACT_FILES) { + if (extract_files(sd, old, new, path)) goto fail; } status = 1; -- cgit v1.2.3