1 Return-Path: <bremner@tesseract.cs.unb.ca>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id D9475431FAF
\r
6 for <notmuch@notmuchmail.org>; Sat, 5 Apr 2014 08:44:39 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id YKXB9MuOeEk8 for <notmuch@notmuchmail.org>;
\r
16 Sat, 5 Apr 2014 08:44:33 -0700 (PDT)
\r
17 Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net
\r
18 [87.98.215.224]) (using TLSv1 with cipher AES256-SHA (256/256 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id A93AD431FAE
\r
21 for <notmuch@notmuchmail.org>; Sat, 5 Apr 2014 08:44:33 -0700 (PDT)
\r
22 Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim
\r
23 4.72) (envelope-from <bremner@tesseract.cs.unb.ca>)
\r
25 for notmuch@notmuchmail.org; Sat, 05 Apr 2014 15:44:14 +0000
\r
26 Received: (nullmailer pid 10909 invoked by uid 1000); Sat, 05 Apr 2014
\r
28 From: David Bremner <david@tethera.net>
\r
29 To: notmuch@notmuchmail.org
\r
30 Subject: v7 gzip dump restore patches
\r
31 Date: Sat, 5 Apr 2014 12:43:50 -0300
\r
32 Message-Id: <1396712636-10640-1-git-send-email-david@tethera.net>
\r
33 X-Mailer: git-send-email 1.9.0
\r
34 X-BeenThere: notmuch@notmuchmail.org
\r
35 X-Mailman-Version: 2.1.13
\r
37 List-Id: "Use and development of the notmuch mail system."
\r
38 <notmuch.notmuchmail.org>
\r
39 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
40 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
42 List-Post: <mailto:notmuch@notmuchmail.org>
\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
44 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
46 X-List-Received-Date: Sat, 05 Apr 2014 15:44:40 -0000
\r
50 id:1396554083-3892-2-git-send-email-david@tethera.net
\r
52 - adds new analogues of strerror
\r
58 diff --git a/configure b/configure
\r
59 index 1d624f7..83b4af7 100755
\r
62 @@ -509,7 +509,7 @@ EOF
\r
63 echo " http://xapian.org/"
\r
65 if [ $have_zlib -eq 0 ]; then
\r
66 - echo " zlib library (including development files such as headers)"
\r
67 + echo " zlib library (>= version 1.2.5.2, including development files such as headers)"
\r
68 echo " http://zlib.net/"
\r
71 diff --git a/notmuch-dump.c b/notmuch-dump.c
\r
72 index 2a7252a..2849eab 100644
\r
73 --- a/notmuch-dump.c
\r
74 +++ b/notmuch-dump.c
\r
75 @@ -127,7 +127,7 @@ notmuch_database_dump (notmuch_database_t *notmuch,
\r
76 dump_format_t output_format,
\r
77 notmuch_bool_t gzip_output)
\r
80 + gzFile output = NULL;
\r
81 const char *mode = gzip_output ? "w9" : "wT";
\r
82 const char *name_for_error = output_file_name ? output_file_name : "stdout";
\r
84 @@ -178,7 +178,10 @@ notmuch_database_dump (notmuch_database_t *notmuch,
\r
87 if (gzclose_w (output) != Z_OK) {
\r
88 + fprintf (stderr, "Error closing %s: %s\n", name_for_error,
\r
89 + gzerror (output, NULL));
\r
95 @@ -192,6 +195,9 @@ notmuch_database_dump (notmuch_database_t *notmuch,
\r
99 + if (ret != EXIT_SUCCESS && output)
\r
100 + (void) gzclose_w (output);
\r
102 if (ret != EXIT_SUCCESS && output_file_name)
\r
103 (void) unlink (tempname);
\r
105 diff --git a/notmuch-restore.c b/notmuch-restore.c
\r
106 index eb5b7b2..7abee0a 100644
\r
107 --- a/notmuch-restore.c
\r
108 +++ b/notmuch-restore.c
\r
109 @@ -129,7 +129,8 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
\r
110 tag_op_list_t *tag_ops;
\r
112 char *input_file_name = NULL;
\r
114 + const char *name_for_error = NULL;
\r
115 + gzFile input = NULL;
\r
117 void *line_ctx = NULL;
\r
119 @@ -157,19 +158,26 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
\r
122 opt_index = parse_arguments (argc, argv, options, 1);
\r
123 - if (opt_index < 0)
\r
124 - return EXIT_FAILURE;
\r
125 + if (opt_index < 0) {
\r
126 + ret = EXIT_FAILURE;
\r
130 + name_for_error = input_file_name ? input_file_name : "stdin";
\r
133 flags |= TAG_FLAG_REMOVE_ALL;
\r
136 if (input_file_name)
\r
137 input = gzopen (input_file_name, "r");
\r
139 int infd = dup (STDIN_FILENO);
\r
141 - fprintf (stderr, "Error duping stdin\n");
\r
142 - return EXIT_FAILURE;
\r
143 + fprintf (stderr, "Error duping stdin: %s\n",
\r
144 + strerror (errno));
\r
145 + ret = EXIT_FAILURE;
\r
148 input = gzdopen (infd, "r");
\r
150 @@ -178,19 +186,22 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
\r
152 if (input == NULL) {
\r
153 fprintf (stderr, "Error opening %s for (gzip) reading: %s\n",
\r
154 - input_file_name ? input_file_name : "stdin", strerror (errno));
\r
155 - return EXIT_FAILURE;
\r
156 + name_for_error, strerror (errno));
\r
157 + ret = EXIT_FAILURE;
\r
161 if (opt_index < argc) {
\r
162 fprintf (stderr, "Unused positional parameter: %s\n", argv[opt_index]);
\r
163 - return EXIT_FAILURE;
\r
164 + ret = EXIT_FAILURE;
\r
168 tag_ops = tag_op_list_create (config);
\r
169 if (tag_ops == NULL) {
\r
170 fprintf (stderr, "Out of memory.\n");
\r
171 - return EXIT_FAILURE;
\r
172 + ret = EXIT_FAILURE;
\r
177 @@ -199,12 +210,17 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
\r
178 status = gz_getline (line_ctx, &line, &line_len, input);
\r
180 /* empty input file not considered an error */
\r
181 - if (status == UTIL_EOF)
\r
182 - return EXIT_SUCCESS;
\r
185 - return EXIT_FAILURE;
\r
186 + if (status == UTIL_EOF) {
\r
187 + ret = EXIT_SUCCESS;
\r
192 + fprintf (stderr, "Error reading (gzipped) input: %s\n",
\r
193 + gz_error_string(status, input));
\r
194 + ret = EXIT_FAILURE;
\r
197 } while ((line_len == 0) ||
\r
198 (line[0] == '#') ||
\r
199 /* the cast is safe because we checked about for line_len < 0 */
\r
200 @@ -269,17 +285,37 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
\r
204 - } while (gz_getline (line_ctx, &line, &line_len, input) == UTIL_SUCCESS);
\r
205 + } while (! (ret = gz_getline (line_ctx, &line, &line_len, input)));
\r
208 - if (line_ctx != NULL)
\r
209 - talloc_free (line_ctx);
\r
210 + /* EOF is normal loop termination condition, UTIL_SUCCESS is
\r
211 + * impossible here */
\r
212 + if (ret == UTIL_EOF) {
\r
213 + ret = UTIL_SUCCESS;
\r
215 + fprintf (stderr, "Error reading (gzipped) input: %s\n",
\r
216 + gz_error_string (ret, input));
\r
219 + /* currently this should not be after DONE: since we don't
\r
220 + * know if the xregcomp was reached
\r
223 if (input_format == DUMP_FORMAT_SUP)
\r
226 - notmuch_database_destroy (notmuch);
\r
228 + if (line_ctx != NULL)
\r
229 + talloc_free (line_ctx);
\r
231 - gzclose_r (input);
\r
233 + notmuch_database_destroy (notmuch);
\r
235 + if (input && gzclose_r (input)) {
\r
236 + fprintf (stderr, "Error closing %s: %s\n",
\r
237 + name_for_error, gzerror (input, NULL));
\r
238 + ret = EXIT_FAILURE;
\r
241 return ret ? EXIT_FAILURE : EXIT_SUCCESS;
\r
243 diff --git a/util/Makefile.local b/util/Makefile.local
\r
244 index e2a5b65..905f237 100644
\r
245 --- a/util/Makefile.local
\r
246 +++ b/util/Makefile.local
\r
247 @@ -4,7 +4,8 @@ dir := util
\r
248 extra_cflags += -I$(srcdir)/$(dir)
\r
250 libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \
\r
251 - $(dir)/string-util.c $(dir)/talloc-extra.c $(dir)/zlib-extra.c
\r
252 + $(dir)/string-util.c $(dir)/talloc-extra.c $(dir)/zlib-extra.c \
\r
255 libutil_modules := $(libutil_c_srcs:.c=.o)
\r
257 diff --git a/util/util.c b/util/util.c
\r
258 new file mode 100644
\r
259 index 0000000..3bd305d
\r
264 +#include "error_util.h"
\r
265 +#include <string.h>
\r
266 +#include <errno.h>
\r
269 +util_error_string (util_status_t errnum)
\r
271 + switch (errnum) {
\r
272 + case UTIL_SUCCESS:
\r
274 + case UTIL_OUT_OF_MEMORY:
\r
275 + return "out of memory";
\r
277 + return "end of file";
\r
279 + return strerror (errno);
\r
280 + case UTIL_GZERROR:
\r
281 + /* we lack context to be more informative here */
\r
282 + return "zlib error";
\r
284 + INTERNAL_ERROR("unexpected error status %d", errnum);
\r
287 diff --git a/util/util.h b/util/util.h
\r
288 index 8663cfc..d12fadb 100644
\r
294 typedef enum util_status {
\r
296 + * No error occurred.
\r
303 UTIL_OUT_OF_MEMORY,
\r
305 + * End of stream reached while attempting to read.
\r
310 + * Low level error occured, consult errno.
\r
314 + * Zlib error occured, call gzerror for details.
\r
320 +util_error_string (util_status_t status);
\r
322 diff --git a/util/zlib-extra.c b/util/zlib-extra.c
\r
323 index 922ab52..cb34845 100644
\r
324 --- a/util/zlib-extra.c
\r
325 +++ b/util/zlib-extra.c
\r
326 @@ -54,9 +54,9 @@ gz_getline (void *talloc_ctx, char **bufptr, ssize_t *bytes_read, gzFile stream)
\r
330 - return UTIL_FILE;
\r
331 + return UTIL_ERRNO;
\r
333 - return UTIL_ERROR;
\r
334 + return UTIL_GZERROR;
\r
338 @@ -75,3 +75,11 @@ gz_getline (void *talloc_ctx, char **bufptr, ssize_t *bytes_read, gzFile stream)
\r
339 *bytes_read = offset;
\r
340 return UTIL_SUCCESS;
\r
343 +const char *gz_error_string (util_status_t status, gzFile file)
\r
345 + if (status == UTIL_GZERROR)
\r
346 + return gzerror (file, NULL);
\r
348 + return util_error_string (status);
\r
350 diff --git a/util/zlib-extra.h b/util/zlib-extra.h
\r
351 index ed67115..dbaa0b9 100644
\r
352 --- a/util/zlib-extra.h
\r
353 +++ b/util/zlib-extra.h
\r
358 -/* Like getline, but read from a gzFile. Allocation is with talloc */
\r
359 +/* Like getline, but read from a gzFile. Allocation is with talloc.
\r
362 + * UTIL_SUCCESS, UTIL_OUT_OF_MEMORY, UTIL_ERRNO, UTIL_GZERROR
\r
363 + * Consult util.h for description
\r
365 + * UTIL_EOF End of file encountered before
\r
366 + * any characters read
\r
369 gz_getline (void *ctx, char **lineptr, ssize_t *bytes_read, gzFile stream);
\r
371 +/* return a suitable error string based on the return status
\r
372 + * from gz_readline
\r
376 +gz_error_string (util_status_t status, gzFile stream);
\r