aboutsummaryrefslogtreecommitdiff
path: root/bin/rdsquashfs/fill_files.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-09-04 19:26:31 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-09-16 09:34:35 +0200
commit0a0cbefc6ebb6174aad3e6f0b8a6dea87aed49da (patch)
tree7b1a69382f7480e442620b6176c1673abcf81b3c /bin/rdsquashfs/fill_files.c
parent4b994ac359757098ebc09263fff9e2290a58de71 (diff)
Remodel file extraction tools to use libfstream
This commit rewrites the libtar write paths to use libfstream insead of a FILE pointer. Also, the libcommon file extraction function is remodeled to use libfstream. In accordance, rdsquashfs, sqfs2tar and sqfsdiff have some minor adjustments made to work with the ported libtar and libcommon. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'bin/rdsquashfs/fill_files.c')
-rw-r--r--bin/rdsquashfs/fill_files.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/bin/rdsquashfs/fill_files.c b/bin/rdsquashfs/fill_files.c
index b75afbf..63ad640 100644
--- a/bin/rdsquashfs/fill_files.c
+++ b/bin/rdsquashfs/fill_files.c
@@ -135,29 +135,31 @@ static int gen_file_list_dfs(const sqfs_tree_node_t *n)
static int fill_files(sqfs_data_reader_t *data, int flags)
{
+ int ret, openflags;
+ ostream_t *fp;
size_t i;
- FILE *fp;
+
+ openflags = OSTREAM_OPEN_OVERWRITE;
+
+ if (flags & UNPACK_NO_SPARSE)
+ openflags |= OSTREAM_OPEN_SPARSE;
for (i = 0; i < num_files; ++i) {
- fp = fopen(files[i].path, "wb");
- if (fp == NULL) {
- fprintf(stderr, "unpacking %s: %s\n",
- files[i].path, strerror(errno));
+ fp = ostream_open_file(files[i].path, openflags);
+ if (fp == NULL)
return -1;
- }
if (!(flags & UNPACK_QUIET))
printf("unpacking %s\n", files[i].path);
- if (sqfs_data_reader_dump(files[i].path, data, files[i].inode,
- fp, block_size,
- (flags & UNPACK_NO_SPARSE) == 0)) {
- fclose(fp);
- return -1;
- }
+ ret = sqfs_data_reader_dump(files[i].path, data, files[i].inode,
+ fp, block_size);
+ if (ret == 0)
+ ret = ostream_flush(fp);
- fflush(fp);
- fclose(fp);
+ sqfs_destroy(fp);
+ if (ret)
+ return -1;
}
return 0;