summaryrefslogtreecommitdiff
path: root/bin/rdsquashfs
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
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')
-rw-r--r--bin/rdsquashfs/Makemodule.am2
-rw-r--r--bin/rdsquashfs/fill_files.c30
-rw-r--r--bin/rdsquashfs/rdsquashfs.c14
3 files changed, 29 insertions, 17 deletions
diff --git a/bin/rdsquashfs/Makemodule.am b/bin/rdsquashfs/Makemodule.am
index e4f3b96..094771c 100644
--- a/bin/rdsquashfs/Makemodule.am
+++ b/bin/rdsquashfs/Makemodule.am
@@ -4,7 +4,7 @@ rdsquashfs_SOURCES += bin/rdsquashfs/restore_fstree.c bin/rdsquashfs/describe.c
rdsquashfs_SOURCES += bin/rdsquashfs/fill_files.c bin/rdsquashfs/dump_xattrs.c
rdsquashfs_SOURCES += bin/rdsquashfs/stat.c
rdsquashfs_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
-rdsquashfs_LDADD = libcommon.a libcompat.a libsquashfs.la
+rdsquashfs_LDADD = libcommon.a libfstream.a libcompat.a libsquashfs.la
rdsquashfs_LDADD += libfstree.a $(LZO_LIBS) $(PTHREAD_LIBS)
dist_man1_MANS += bin/rdsquashfs/rdsquashfs.1
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;
diff --git a/bin/rdsquashfs/rdsquashfs.c b/bin/rdsquashfs/rdsquashfs.c
index 1c11afa..5b6ce19 100644
--- a/bin/rdsquashfs/rdsquashfs.c
+++ b/bin/rdsquashfs/rdsquashfs.c
@@ -115,18 +115,28 @@ int main(int argc, char **argv)
if (stat_file(n))
goto out;
break;
- case OP_CAT:
+ case OP_CAT: {
+ ostream_t *fp;
+
if (!S_ISREG(n->inode->base.mode)) {
fprintf(stderr, "/%s: not a regular file\n",
opt.cmdpath);
goto out;
}
+ fp = ostream_open_stdout();
+ if (fp == NULL)
+ goto out;
+
if (sqfs_data_reader_dump(opt.cmdpath, data, n->inode,
- stdout, super.block_size, false)) {
+ fp, super.block_size)) {
+ sqfs_destroy(fp);
goto out;
}
+
+ sqfs_destroy(fp);
break;
+ }
case OP_UNPACK:
if (opt.unpack_root != NULL) {
if (mkdir_p(opt.unpack_root))