From 851bb334c29a09e3ea706cc610c67667161165fa Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Wed, 21 Aug 2019 13:46:26 +0200 Subject: Consistently use old/new nomenclature in sqfsdiff Signed-off-by: David Oberhollenzer --- difftool/compare_files.c | 72 +++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 35 deletions(-) (limited to 'difftool/compare_files.c') diff --git a/difftool/compare_files.c b/difftool/compare_files.c index 89c5f5c..04749c3 100644 --- a/difftool/compare_files.c +++ b/difftool/compare_files.c @@ -6,90 +6,92 @@ */ #include "difftool.h" -static unsigned char a_buf[MAX_WINDOW_SIZE]; -static unsigned char b_buf[MAX_WINDOW_SIZE]; +static unsigned char old_buf[MAX_WINDOW_SIZE]; +static unsigned char new_buf[MAX_WINDOW_SIZE]; -int compare_files(file_info_t *a, file_info_t *b, const char *path) +int compare_files(file_info_t *old, file_info_t *new, const char *path) { - char second_name[strlen(second_path) + strlen(path) + 2]; - char first_name[strlen(first_path) + strlen(path) + 2]; - int afd = -1, bfd = -1, status = 0; + char new_name[strlen(new_path) + strlen(path) + 2]; + char old_name[strlen(old_path) + strlen(path) + 2]; + int old_fd = -1, new_fd = -1, status = 0; uint64_t offset, diff; ssize_t ret; - if (a->size != b->size) + if (old->size != new->size) goto out_different; if (compare_flags & COMPARE_NO_CONTENTS) return 0; - if (a_is_dir) { - sprintf(first_name, "%s/%s", first_path, path); + if (old_is_dir) { + sprintf(old_name, "%s/%s", old_path, path); - afd = open(first_name, O_RDONLY); - if (afd < 0) { - perror(first_name); + old_fd = open(old_name, O_RDONLY); + if (old_fd < 0) { + perror(old_name); goto fail; } } - if (b_is_dir) { - sprintf(second_name, "%s/%s", second_path, path); + if (new_is_dir) { + sprintf(new_name, "%s/%s", new_path, path); - bfd = open(second_name, O_RDONLY); - if (bfd < 0) { - perror(second_name); + new_fd = open(new_name, O_RDONLY); + if (new_fd < 0) { + perror(new_name); goto fail; } } - for (offset = 0; offset < a->size; offset += diff) { - diff = a->size - offset; + for (offset = 0; offset < old->size; offset += diff) { + diff = old->size - offset; if (diff > MAX_WINDOW_SIZE) diff = MAX_WINDOW_SIZE; - if (a_is_dir) { - if (read_data_at(first_name, offset, afd, a_buf, diff)) + if (old_is_dir) { + if (read_data_at(old_name, offset, old_fd, + old_buf, diff)) goto out; } else { - ret = data_reader_read(sqfs_a.data, a, offset, - a_buf, diff); + ret = data_reader_read(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, first_path); + path, old_path); return -1; } } - if (b_is_dir) { - if (read_data_at(second_name, offset, bfd, b_buf, diff)) + if (new_is_dir) { + if (read_data_at(new_name, offset, new_fd, + new_buf, diff)) goto out; } else { - ret = data_reader_read(sqfs_b.data, b, offset, - b_buf, diff); + ret = data_reader_read(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, second_path); + path, new_path); return -1; } } - if (memcmp(a_buf, b_buf, diff) != 0) + if (memcmp(old_buf, new_buf, diff) != 0) goto out_different; } out: - if (afd >= 0) - close(afd); - if (bfd >= 0) - close(bfd); + if (old_fd >= 0) + close(old_fd); + if (new_fd >= 0) + close(new_fd); return status; fail: status = -1; goto out; out_different: if (compare_flags & COMPARE_EXTRACT_FILES) { - if (extract_files(a, b, path)) + if (extract_files(old, new, path)) goto fail; } status = 1; -- cgit v1.2.3