diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-04-27 11:59:02 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-04-27 11:59:02 +0200 |
commit | 20b0d509f67dea802706cd6b80b5e20d14988931 (patch) | |
tree | 3a87ea358b1206f6823777693d109896d6908283 /bin/sqfsdiff/extract.c | |
parent | 9e332a2d3eddcc262476ac263e03df021b3c44b4 (diff) |
Cleanup directory structure of the binary programs
Instead of having the binary programs in randomly named subdirectories,
move all of them to a "bin" subdirectory, similar to the utility
libraries that have subdirectories within "lib" and give the
subdirectories the propper names (e.g. have gensquashfs source in a
directory *actually* named "gensquashfs").
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'bin/sqfsdiff/extract.c')
-rw-r--r-- | bin/sqfsdiff/extract.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/bin/sqfsdiff/extract.c b/bin/sqfsdiff/extract.c new file mode 100644 index 0000000..979572a --- /dev/null +++ b/bin/sqfsdiff/extract.c @@ -0,0 +1,57 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * extract.c + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#include "sqfsdiff.h" + +static int extract(sqfs_data_reader_t *data, const sqfs_inode_generic_t *inode, + const char *prefix, const char *path, size_t block_size) +{ + char *ptr, *temp; + FILE *fp; + + temp = alloca(strlen(prefix) + strlen(path) + 2); + sprintf(temp, "%s/%s", prefix, path); + + ptr = strrchr(temp, '/'); + *ptr = '\0'; + if (mkdir_p(temp)) + return -1; + *ptr = '/'; + + fp = fopen(temp, "wb"); + if (fp == NULL) { + perror(temp); + return -1; + } + + if (sqfs_data_reader_dump(path, data, inode, fp, block_size, true)) { + fclose(fp); + return -1; + } + + fflush(fp); + fclose(fp); + return 0; +} + +int extract_files(sqfsdiff_t *sd, const sqfs_inode_generic_t *old, + const sqfs_inode_generic_t *new, + const char *path) +{ + if (old != NULL) { + if (extract(sd->sqfs_old.data, old, "old", + path, sd->sqfs_old.super.block_size)) + return -1; + } + + if (new != NULL) { + if (extract(sd->sqfs_new.data, new, "new", + path, sd->sqfs_new.super.block_size)) + return -1; + } + + return 0; +} |