v7 gzip dump restore patches
David Bremner writes: > Supercedes > > id:1396554083-3892-2-git-send-email-david at tethera.net > > - adds new analogues of strerror > - util_error_string > - gz_error_string > pushed, amended as suggested by Austin and Tomi. d
Re: v7 gzip dump restore patches
David Bremner writes: > Supercedes > > id:1396554083-3892-2-git-send-email-da...@tethera.net > > - adds new analogues of strerror > - util_error_string > - gz_error_string > pushed, amended as suggested by Austin and Tomi. d ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
v7 gzip dump restore patches
On Sat, 05 Apr 2014, David Bremner wrote: > Supercedes > > id:1396554083-3892-2-git-send-email-david at tethera.net > > - adds new analogues of strerror > - util_error_string > - gz_error_string LGTM other than the two nits I pointed out. I'd be happy to have the fixes for those simply amended in when you apply.
Re: v7 gzip dump restore patches
On Sat, 05 Apr 2014, David Bremner wrote: > Supercedes > > id:1396554083-3892-2-git-send-email-da...@tethera.net > > - adds new analogues of strerror > - util_error_string > - gz_error_string LGTM other than the two nits I pointed out. I'd be happy to have the fixes for those simply amended in when you apply. ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
v7 gzip dump restore patches
Supercedes id:1396554083-3892-2-git-send-email-david at tethera.net - adds new analogues of strerror - util_error_string - gz_error_string Interdiff: diff --git a/configure b/configure index 1d624f7..83b4af7 100755 --- a/configure +++ b/configure @@ -509,7 +509,7 @@ EOF echo " http://xapian.org/"; fi if [ $have_zlib -eq 0 ]; then - echo " zlib library (including development files such as headers)" + echo " zlib library (>= version 1.2.5.2, including development files such as headers)" echo " http://zlib.net/"; echo fi diff --git a/notmuch-dump.c b/notmuch-dump.c index 2a7252a..2849eab 100644 --- a/notmuch-dump.c +++ b/notmuch-dump.c @@ -127,7 +127,7 @@ notmuch_database_dump (notmuch_database_t *notmuch, dump_format_t output_format, notmuch_bool_t gzip_output) { -gzFile output; +gzFile output = NULL; const char *mode = gzip_output ? "w9" : "wT"; const char *name_for_error = output_file_name ? output_file_name : "stdout"; @@ -178,7 +178,10 @@ notmuch_database_dump (notmuch_database_t *notmuch, } if (gzclose_w (output) != Z_OK) { + fprintf (stderr, "Error closing %s: %s\n", name_for_error, +gzerror (output, NULL)); ret = EXIT_FAILURE; + output = NULL; goto DONE; } @@ -192,6 +195,9 @@ notmuch_database_dump (notmuch_database_t *notmuch, } DONE: +if (ret != EXIT_SUCCESS && output) + (void) gzclose_w (output); + if (ret != EXIT_SUCCESS && output_file_name) (void) unlink (tempname); diff --git a/notmuch-restore.c b/notmuch-restore.c index eb5b7b2..7abee0a 100644 --- a/notmuch-restore.c +++ b/notmuch-restore.c @@ -129,7 +129,8 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]) tag_op_list_t *tag_ops; char *input_file_name = NULL; -gzFile input; +const char *name_for_error = NULL; +gzFile input = NULL; char *line = NULL; void *line_ctx = NULL; ssize_t line_len; @@ -157,19 +158,26 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]) }; opt_index = parse_arguments (argc, argv, options, 1); -if (opt_index < 0) - return EXIT_FAILURE; +if (opt_index < 0) { + ret = EXIT_FAILURE; + goto DONE; +} + +name_for_error = input_file_name ? input_file_name : "stdin"; if (! accumulate) flags |= TAG_FLAG_REMOVE_ALL; +errno = 0; if (input_file_name) input = gzopen (input_file_name, "r"); else { int infd = dup (STDIN_FILENO); if (infd < 0) { - fprintf (stderr, "Error duping stdin\n"); - return EXIT_FAILURE; + fprintf (stderr, "Error duping stdin: %s\n", +strerror (errno)); + ret = EXIT_FAILURE; + goto DONE; } input = gzdopen (infd, "r"); if (! input) @@ -178,19 +186,22 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]) if (input == NULL) { fprintf (stderr, "Error opening %s for (gzip) reading: %s\n", -input_file_name ? input_file_name : "stdin", strerror (errno)); - return EXIT_FAILURE; +name_for_error, strerror (errno)); + ret = EXIT_FAILURE; + goto DONE; } if (opt_index < argc) { fprintf (stderr, "Unused positional parameter: %s\n", argv[opt_index]); - return EXIT_FAILURE; + ret = EXIT_FAILURE; + goto DONE; } tag_ops = tag_op_list_create (config); if (tag_ops == NULL) { fprintf (stderr, "Out of memory.\n"); - return EXIT_FAILURE; + ret = EXIT_FAILURE; + goto DONE; } do { @@ -199,12 +210,17 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]) status = gz_getline (line_ctx, &line, &line_len, input); /* empty input file not considered an error */ - if (status == UTIL_EOF) - return EXIT_SUCCESS; - - if (status) - return EXIT_FAILURE; + if (status == UTIL_EOF) { + ret = EXIT_SUCCESS; + goto DONE; + } + if (status) { + fprintf (stderr, "Error reading (gzipped) input: %s\n", +gz_error_string(status, input)); + ret = EXIT_FAILURE; + goto DONE; + } } while ((line_len == 0) || (line[0] == '#') || /* the cast is safe because we checked about for line_len < 0 */ @@ -269,17 +285,37 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]) if (ret) break; -} while (gz_getline (line_ctx, &line, &line_len, input) == UTIL_SUCCESS); +} while (! (ret = gz_getline (line_ctx, &line, &line_len, input))); + -if (line_ctx != NULL) - talloc_free (line_ctx); +/* EOF is normal loop termination condition, UTIL_SUC
v7 gzip dump restore patches
Supercedes id:1396554083-3892-2-git-send-email-da...@tethera.net - adds new analogues of strerror - util_error_string - gz_error_string Interdiff: diff --git a/configure b/configure index 1d624f7..83b4af7 100755 --- a/configure +++ b/configure @@ -509,7 +509,7 @@ EOF echo " http://xapian.org/"; fi if [ $have_zlib -eq 0 ]; then - echo " zlib library (including development files such as headers)" + echo " zlib library (>= version 1.2.5.2, including development files such as headers)" echo " http://zlib.net/"; echo fi diff --git a/notmuch-dump.c b/notmuch-dump.c index 2a7252a..2849eab 100644 --- a/notmuch-dump.c +++ b/notmuch-dump.c @@ -127,7 +127,7 @@ notmuch_database_dump (notmuch_database_t *notmuch, dump_format_t output_format, notmuch_bool_t gzip_output) { -gzFile output; +gzFile output = NULL; const char *mode = gzip_output ? "w9" : "wT"; const char *name_for_error = output_file_name ? output_file_name : "stdout"; @@ -178,7 +178,10 @@ notmuch_database_dump (notmuch_database_t *notmuch, } if (gzclose_w (output) != Z_OK) { + fprintf (stderr, "Error closing %s: %s\n", name_for_error, +gzerror (output, NULL)); ret = EXIT_FAILURE; + output = NULL; goto DONE; } @@ -192,6 +195,9 @@ notmuch_database_dump (notmuch_database_t *notmuch, } DONE: +if (ret != EXIT_SUCCESS && output) + (void) gzclose_w (output); + if (ret != EXIT_SUCCESS && output_file_name) (void) unlink (tempname); diff --git a/notmuch-restore.c b/notmuch-restore.c index eb5b7b2..7abee0a 100644 --- a/notmuch-restore.c +++ b/notmuch-restore.c @@ -129,7 +129,8 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]) tag_op_list_t *tag_ops; char *input_file_name = NULL; -gzFile input; +const char *name_for_error = NULL; +gzFile input = NULL; char *line = NULL; void *line_ctx = NULL; ssize_t line_len; @@ -157,19 +158,26 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]) }; opt_index = parse_arguments (argc, argv, options, 1); -if (opt_index < 0) - return EXIT_FAILURE; +if (opt_index < 0) { + ret = EXIT_FAILURE; + goto DONE; +} + +name_for_error = input_file_name ? input_file_name : "stdin"; if (! accumulate) flags |= TAG_FLAG_REMOVE_ALL; +errno = 0; if (input_file_name) input = gzopen (input_file_name, "r"); else { int infd = dup (STDIN_FILENO); if (infd < 0) { - fprintf (stderr, "Error duping stdin\n"); - return EXIT_FAILURE; + fprintf (stderr, "Error duping stdin: %s\n", +strerror (errno)); + ret = EXIT_FAILURE; + goto DONE; } input = gzdopen (infd, "r"); if (! input) @@ -178,19 +186,22 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]) if (input == NULL) { fprintf (stderr, "Error opening %s for (gzip) reading: %s\n", -input_file_name ? input_file_name : "stdin", strerror (errno)); - return EXIT_FAILURE; +name_for_error, strerror (errno)); + ret = EXIT_FAILURE; + goto DONE; } if (opt_index < argc) { fprintf (stderr, "Unused positional parameter: %s\n", argv[opt_index]); - return EXIT_FAILURE; + ret = EXIT_FAILURE; + goto DONE; } tag_ops = tag_op_list_create (config); if (tag_ops == NULL) { fprintf (stderr, "Out of memory.\n"); - return EXIT_FAILURE; + ret = EXIT_FAILURE; + goto DONE; } do { @@ -199,12 +210,17 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]) status = gz_getline (line_ctx, &line, &line_len, input); /* empty input file not considered an error */ - if (status == UTIL_EOF) - return EXIT_SUCCESS; - - if (status) - return EXIT_FAILURE; + if (status == UTIL_EOF) { + ret = EXIT_SUCCESS; + goto DONE; + } + if (status) { + fprintf (stderr, "Error reading (gzipped) input: %s\n", +gz_error_string(status, input)); + ret = EXIT_FAILURE; + goto DONE; + } } while ((line_len == 0) || (line[0] == '#') || /* the cast is safe because we checked about for line_len < 0 */ @@ -269,17 +285,37 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]) if (ret) break; -} while (gz_getline (line_ctx, &line, &line_len, input) == UTIL_SUCCESS); +} while (! (ret = gz_getline (line_ctx, &line, &line_len, input))); + -if (line_ctx != NULL) - talloc_free (line_ctx); +/* EOF is normal loop termination condi