From ec72abd9dd63bbff4534ec77e97b1a6cadfc3cf8 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Fri, 18 Mar 2016 22:16:46 +0200 Subject: genfile: new option --quiet * tests/genfile.c: New option --quite: suppress error exit if the created file is not sparse. * doc/genfile.texi: Document --quiet. --- doc/genfile.texi | 10 ++++++++-- tests/genfile.c | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/doc/genfile.texi b/doc/genfile.texi index bd2e505..e35f34b 100644 --- a/doc/genfile.texi +++ b/doc/genfile.texi @@ -181,8 +181,14 @@ letters @samp{A}, @samp{B}, @samp{C} and @samp{D}. @item 1053184 @tab 2048000 @tab Zero bytes @end multitable - The exit code of @command{genfile --status} command is @code{0} -only if created file is actually sparse. +@cindex --quite, option + The exit code of @command{genfile --sparse} command is @code{0} +only if created file is actually sparse. If it is not, the +appropriate error message is displayed and the command exists with +code @code{1}. The @option{--quite} (@option{-q}) option suppresses +this behavior. If @option{--quite} is given, @command{genfile +--sparse} exits with code @code{0} if it was able to create the file, +whether the resulting file is sparse or not. @node Status Mode @appendixsec Status Mode diff --git a/tests/genfile.c b/tests/genfile.c index 4699d21..336788f 100644 --- a/tests/genfile.c +++ b/tests/genfile.c @@ -107,6 +107,9 @@ struct timespec touch_time; /* Verbose mode */ int verbose; +/* Quiet mode */ +int quiet; + const char *argp_program_version = "genfile (" PACKAGE ") " VERSION; const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">"; static char doc[] = N_("genfile manipulates data files for GNU paxutils test suite.\n" @@ -145,7 +148,8 @@ static struct argp_option options[] = { {"seek", OPT_SEEK, N_("OFFSET"), 0, N_("Seek to the given offset before writing data"), GRP+1 }, - + {"quiet", 'q', NULL, 0, + N_("Suppress non-fatal diagnostic messages") }, #undef GRP #define GRP 10 {NULL, 0, NULL, 0, @@ -266,11 +270,11 @@ verify_file (char *file_name) error (0, errno, _("stat(%s) failed"), file_name); if (st.st_size != file_length + seek_offset) - error (1, 0, _("requested file length %lu, actual %lu"), + error (EXIT_FAILURE, 0, _("requested file length %lu, actual %lu"), (unsigned long)st.st_size, (unsigned long)file_length); - if (mode == mode_sparse && !ST_IS_SPARSE (st)) - error (1, 0, _("created file is not sparse")); + if (!quiet && mode == mode_sparse && !ST_IS_SPARSE (st)) + error (EXIT_FAILURE, 0, _("created file is not sparse")); } } @@ -326,6 +330,10 @@ parse_opt (int key, char *arg, struct argp_state *state) block_size = get_size (arg, 0); break; + case 'q': + quiet = 1; + break; + case 's': mode = mode_sparse; break; -- cgit v1.2.1