mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 10:58:10 +01:00
cli/dump: define GZPRINTF macro and use it in place of gzprintf
This will at least catch errors, and can be replaced with more sophisticated error handling where appropriate.
This commit is contained in:
parent
0211272843
commit
0d0918f604
2 changed files with 16 additions and 12 deletions
|
@ -497,6 +497,10 @@ print_status_gzbytes (const char *loc,
|
||||||
gzFile file,
|
gzFile file,
|
||||||
int bytes);
|
int bytes);
|
||||||
|
|
||||||
|
/* the __location__ macro is defined in talloc.h */
|
||||||
|
#define ASSERT_GZBYTES(file, bytes) ((print_status_gzbytes (__location__, file, bytes)) ? exit (1) : 0)
|
||||||
|
#define GZPRINTF(file, fmt, ...) ASSERT_GZBYTES (file, gzprintf (file, fmt, ##__VA_ARGS__));
|
||||||
|
|
||||||
#include "command-line-arguments.h"
|
#include "command-line-arguments.h"
|
||||||
|
|
||||||
extern const char *notmuch_requested_db_uuid;
|
extern const char *notmuch_requested_db_uuid;
|
||||||
|
|
|
@ -42,7 +42,7 @@ database_dump_config (notmuch_database_t *notmuch, gzFile output)
|
||||||
notmuch_config_list_key (list));
|
notmuch_config_list_key (list));
|
||||||
goto DONE;
|
goto DONE;
|
||||||
}
|
}
|
||||||
gzprintf (output, "#@ %s", buffer);
|
GZPRINTF (output, "#@ %s", buffer);
|
||||||
|
|
||||||
if (hex_encode (notmuch, notmuch_config_list_value (list),
|
if (hex_encode (notmuch, notmuch_config_list_value (list),
|
||||||
&buffer, &buffer_size) != HEX_SUCCESS) {
|
&buffer, &buffer_size) != HEX_SUCCESS) {
|
||||||
|
@ -51,7 +51,7 @@ database_dump_config (notmuch_database_t *notmuch, gzFile output)
|
||||||
goto DONE;
|
goto DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gzprintf (output, " %s\n", buffer);
|
GZPRINTF (output, " %s\n", buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = EXIT_SUCCESS;
|
ret = EXIT_SUCCESS;
|
||||||
|
@ -71,7 +71,7 @@ print_dump_header (gzFile output, int output_format, int include)
|
||||||
{
|
{
|
||||||
const char *sep = "";
|
const char *sep = "";
|
||||||
|
|
||||||
gzprintf (output, "#notmuch-dump %s:%d ",
|
GZPRINTF (output, "#notmuch-dump %s:%d ",
|
||||||
(output_format == DUMP_FORMAT_SUP) ? "sup" : "batch-tag",
|
(output_format == DUMP_FORMAT_SUP) ? "sup" : "batch-tag",
|
||||||
NOTMUCH_DUMP_VERSION);
|
NOTMUCH_DUMP_VERSION);
|
||||||
|
|
||||||
|
@ -80,11 +80,11 @@ print_dump_header (gzFile output, int output_format, int include)
|
||||||
sep = ",";
|
sep = ",";
|
||||||
}
|
}
|
||||||
if (include & DUMP_INCLUDE_PROPERTIES) {
|
if (include & DUMP_INCLUDE_PROPERTIES) {
|
||||||
gzprintf (output, "%sproperties", sep);
|
GZPRINTF (output, "%sproperties", sep);
|
||||||
sep = ",";
|
sep = ",";
|
||||||
}
|
}
|
||||||
if (include & DUMP_INCLUDE_TAGS) {
|
if (include & DUMP_INCLUDE_TAGS) {
|
||||||
gzprintf (output, "%stags", sep);
|
GZPRINTF (output, "%stags", sep);
|
||||||
}
|
}
|
||||||
gzputs (output, "\n");
|
gzputs (output, "\n");
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ dump_properties_message (void *ctx,
|
||||||
fprintf (stderr, "Error: failed to hex-encode message-id %s\n", message_id);
|
fprintf (stderr, "Error: failed to hex-encode message-id %s\n", message_id);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
gzprintf (output, "#= %s", *buffer_p);
|
GZPRINTF (output, "#= %s", *buffer_p);
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,18 +126,18 @@ dump_properties_message (void *ctx,
|
||||||
fprintf (stderr, "Error: failed to hex-encode key %s\n", key);
|
fprintf (stderr, "Error: failed to hex-encode key %s\n", key);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
gzprintf (output, " %s", *buffer_p);
|
GZPRINTF (output, " %s", *buffer_p);
|
||||||
|
|
||||||
if (hex_encode (ctx, val, buffer_p, size_p) != HEX_SUCCESS) {
|
if (hex_encode (ctx, val, buffer_p, size_p) != HEX_SUCCESS) {
|
||||||
fprintf (stderr, "Error: failed to hex-encode value %s\n", val);
|
fprintf (stderr, "Error: failed to hex-encode value %s\n", val);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
gzprintf (output, "=%s", *buffer_p);
|
GZPRINTF (output, "=%s", *buffer_p);
|
||||||
}
|
}
|
||||||
notmuch_message_properties_destroy (list);
|
notmuch_message_properties_destroy (list);
|
||||||
|
|
||||||
if (! first)
|
if (! first)
|
||||||
gzprintf (output, "\n", *buffer_p);
|
GZPRINTF (output, "\n", *buffer_p);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ dump_tags_message (void *ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (output_format == DUMP_FORMAT_SUP) {
|
if (output_format == DUMP_FORMAT_SUP) {
|
||||||
gzprintf (output, "%s (", message_id);
|
GZPRINTF (output, "%s (", message_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (notmuch_tags_t *tags = notmuch_message_get_tags (message);
|
for (notmuch_tags_t *tags = notmuch_message_get_tags (message);
|
||||||
|
@ -187,7 +187,7 @@ dump_tags_message (void *ctx,
|
||||||
tag_str);
|
tag_str);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
gzprintf (output, "+%s", *buffer_p);
|
GZPRINTF (output, "+%s", *buffer_p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@ dump_tags_message (void *ctx,
|
||||||
message_id, strerror (errno));
|
message_id, strerror (errno));
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
gzprintf (output, " -- %s\n", *buffer_p);
|
GZPRINTF (output, " -- %s\n", *buffer_p);
|
||||||
}
|
}
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue