summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-03 15:22:28 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-03 15:28:40 +0200
commite981f2e460092e5ae6ad58a60869b78d7f50ec10 (patch)
tree7911d99b0ab70a1d8eb92fed244cbc8761b4bf72
parent70dcf39f5926a66d76eb9fde2cbaef4b6a23a9e1 (diff)
Add no-skip option to sqfs2tar
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--doc/sqfs2tar.16
-rw-r--r--lib/tar/write_header.c2
-rw-r--r--tar/sqfs2tar.c27
3 files changed, 30 insertions, 5 deletions
diff --git a/doc/sqfs2tar.1 b/doc/sqfs2tar.1
index b732d06..c7389ed 100644
--- a/doc/sqfs2tar.1
+++ b/doc/sqfs2tar.1
@@ -13,6 +13,9 @@ work on tar archives.
.PP
Possible options:
.TP
+\fB\-\-no\-skip\fR, \fB\-s\fR
+Abort if file cannot be stored in a tar record instead of skipping it.
+.TP
\fB\-\-help\fR, \fB\-h\fR
Print help text and exit.
.TP
@@ -28,7 +31,8 @@ It is not possible to store socket files in a tar or pax archive. Also, in the
current implementation, all extended attribuates are lost.
If any file or directory is encountered that cannot be converted, it is
-skipped and a warning is written to stderr.
+skipped and a warning is written to stderr. Unless the \fB\-\-no\-skip\fR
+option is set, which aborts processing if a file cannot be converted.
.SH EXAMPLES
Turn a squashfs image into a tar archive:
.IP
diff --git a/lib/tar/write_header.c b/lib/tar/write_header.c
index 79fa49a..70acb1a 100644
--- a/lib/tar/write_header.c
+++ b/lib/tar/write_header.c
@@ -171,6 +171,6 @@ int write_tar_header(int fd, const struct stat *sb, const char *name,
return write_header(fd, sb, name, slink_target, type);
out_skip:
- fprintf(stderr, "WARNING: skipping '%s' (%s)\n", name, reason);
+ fprintf(stderr, "WARNING: %s: %s\n", name, reason);
return 1;
}
diff --git a/tar/sqfs2tar.c b/tar/sqfs2tar.c
index e568bb4..76c0d74 100644
--- a/tar/sqfs2tar.c
+++ b/tar/sqfs2tar.c
@@ -17,11 +17,12 @@
#include <stdio.h>
static struct option long_opts[] = {
+ { "no-skip", no_argument, NULL, 's' },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
};
-static const char *short_opts = "hV";
+static const char *short_opts = "shV";
static const char *usagestr =
"Usage: sqfs2tar [OPTIONS...] <sqfsfile>\n"
@@ -31,6 +32,10 @@ static const char *usagestr =
"\n"
"Possible options:\n"
"\n"
+" --no-skip Abort if a file cannot be stored in a tar\n"
+" archive. By default, it is simply skipped\n"
+" and a warning is written to stderr."
+"\n"
" --help, -h Print help text and exit.\n"
" --version, -V Print version information and exit.\n"
"\n"
@@ -43,6 +48,7 @@ static const char *usagestr =
static const char *filename;
static unsigned int record_counter;
+static bool dont_skip = false;
static void process_args(int argc, char **argv)
{
@@ -54,6 +60,9 @@ static void process_args(int argc, char **argv)
break;
switch (i) {
+ case 's':
+ dont_skip = true;
+ break;
case 'h':
fputs(usagestr, stdout);
exit(EXIT_SUCCESS);
@@ -124,12 +133,24 @@ static int write_tree_dfs(fstree_t *fs, tree_node_t *n, data_reader_t *data)
target = S_ISLNK(sb.st_mode) ? n->data.slink_target : NULL;
ret = write_tar_header(STDOUT_FILENO, &sb, name, target,
record_counter++);
+
+ if (ret > 0) {
+ if (dont_skip) {
+ fputs("Not allowed to skip files, aborting!\n",
+ stderr);
+ ret = -1;
+ } else {
+ fprintf(stderr, "Skipping %s\n", name);
+ ret = 0;
+ }
+ free(name);
+ return ret;
+ }
+
free(name);
if (ret < 0)
return -1;
- if (ret > 0)
- return 0;
if (S_ISREG(n->mode)) {
if (data_reader_dump_file(data, n->data.file,