aboutsummaryrefslogtreecommitdiff
path: root/difftool/compare_files.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-21 14:04:43 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-21 14:04:43 +0200
commit4ff2b4f689f4e530b6c6f3eed17a595f7ccf56fb (patch)
tree1e453c616d34a1547eb8e62949337e8361c6b31e /difftool/compare_files.c
parent5cbc1267e5dc42149eeb07883f5f6239d22388e9 (diff)
Isolate sqfsdiff global state and split off option processing
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'difftool/compare_files.c')
-rw-r--r--difftool/compare_files.c33
1 files changed, 17 insertions, 16 deletions
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;