status: add print_status_gzbytes

This is in the client code, rather than libnotmuch_util, because it
prints to stderr. Also it in pretends to generate notmuch status
codes.
This commit is contained in:
David Bremner 2020-04-12 20:17:20 -03:00
parent 2c1f783f5f
commit 0211272843
2 changed files with 21 additions and 1 deletions

View file

@ -49,6 +49,7 @@
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <ctype.h> #include <ctype.h>
#include <zlib.h>
#include "talloc-extra.h" #include "talloc-extra.h"
#include "crypto.h" #include "crypto.h"
@ -469,7 +470,7 @@ notmuch_database_dump (notmuch_database_t *notmuch,
dump_include_t include, dump_include_t include,
bool gzip_output); bool gzip_output);
/* If status is non-zero (i.e. error) print appropriate /* If status indicates error print appropriate
* messages to stderr. * messages to stderr.
*/ */
@ -491,6 +492,11 @@ print_status_database (const char *loc,
int int
status_to_exit (notmuch_status_t status); status_to_exit (notmuch_status_t status);
notmuch_status_t
print_status_gzbytes (const char *loc,
gzFile file,
int bytes);
#include "command-line-arguments.h" #include "command-line-arguments.h"
extern const char *notmuch_requested_db_uuid; extern const char *notmuch_requested_db_uuid;

View file

@ -72,3 +72,17 @@ status_to_exit (notmuch_status_t status)
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} }
notmuch_status_t
print_status_gzbytes (const char *loc, gzFile file, int bytes)
{
if (bytes <= 0) {
int errnum;
const char *errstr = gzerror (file, &errnum);
fprintf (stderr, "%s: zlib error %s (%d)\n", loc, errstr, errnum);
return NOTMUCH_STATUS_FILE_ERROR;
} else {
return NOTMUCH_STATUS_SUCCESS;
}
}