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/extract.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 difftool/extract.c (limited to 'difftool/extract.c') diff --git a/difftool/extract.c b/difftool/extract.c new file mode 100644 index 0000000..9d84265 --- /dev/null +++ b/difftool/extract.c @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * extract.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "difftool.h" + +static int extract(data_reader_t *data, file_info_t *fi, + const char *path, char prefix) +{ + char *ptr, *temp = alloca(strlen(path) + 3); + int fd; + + temp[0] = prefix; + temp[1] = '/'; + strcpy(temp + 2, path); + + ptr = strrchr(temp, '/'); + *ptr = '\0'; + if (mkdir_p(temp)) + return -1; + *ptr = '/'; + + fd = open(temp, O_CREAT | O_EXCL | O_WRONLY, 0600); + if (fd < 0) { + perror(temp); + return -1; + } + + if (data_reader_dump_file(data, fi, fd, true)) { + close(fd); + return -1; + } + + close(fd); + return 0; +} + +int extract_files(file_info_t *a, file_info_t *b, const char *path) +{ + if (a != NULL) { + if (extract(sqfs_a.data, a, path, 'a')) + return -1; + } + + if (b != NULL) { + if (extract(sqfs_b.data, b, path, 'b')) + return -1; + } + return 0; +} -- cgit v1.2.3