Re: [PATCH v4 01/16] add util/search-path.{c, h} to test for executables in $PATH
[notmuch-archives.git] / 57 / 49eac47125558a7c0f04d0c2f02d996a2e66e3
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 4C743431FAF\r
6         for <notmuch@notmuchmail.org>; Thu,  3 Apr 2014 19:44:15 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\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 ofKy6FAUZxIL for <notmuch@notmuchmail.org>;\r
16         Thu,  3 Apr 2014 19:44:10 -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 0DCEC431FD4\r
21         for <notmuch@notmuchmail.org>; Thu,  3 Apr 2014 19:44:00 -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
24         id 1WVtYQ-00018I-SI\r
25         for notmuch@notmuchmail.org; Fri, 04 Apr 2014 02:08:26 +0000\r
26 Received: (nullmailer pid 4009 invoked by uid 1000); Thu, 03 Apr 2014\r
27         19:41:39 -0000\r
28 From: David Bremner <david@tethera.net>\r
29 To: notmuch@notmuchmail.org\r
30 Subject: v6 gzipped dump/restore \r
31 Date: Thu,  3 Apr 2014 16:41:17 -0300\r
32 Message-Id: <1396554083-3892-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
36 Precedence: list\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: Fri, 04 Apr 2014 02:44:15 -0000\r
47 \r
48 I hope I got all the comments from Tomi and Austin. Interdiff below.\r
49 \r
50 I ended up collapsing two patches while I was revising, since it\r
51 seemed artificial to do some of the changes twice to keep the gzipped\r
52 and atomic features as seperate patches.\r
53 \r
54 \r
55 diff --git a/INSTALL b/INSTALL\r
56 index df318fa..b543c50 100644\r
57 --- a/INSTALL\r
58 +++ b/INSTALL\r
59 @@ -67,6 +67,9 @@ Talloc, and zlib which are each described below:\r
60         by Xapian, so if you installed that you will already have\r
61         zlib. You may need to install the zlib headers separately.\r
62  \r
63 +       Notmuch needs the transparent write feature of zlib introduced\r
64 +       in version 1.2.5.2 (Dec. 2011).\r
65 +\r
66         zlib is available from http://zlib.net\r
67  \r
68  Building Documentation\r
69 diff --git a/configure b/configure\r
70 index d685ab3..1d624f7 100755\r
71 --- a/configure\r
72 +++ b/configure\r
73 @@ -340,9 +340,9 @@ else\r
74      errors=$((errors + 1))\r
75  fi\r
76  \r
77 -printf "Checking for zlib development files... "\r
78 +printf "Checking for zlib (>= 1.2.5.2)... "\r
79  have_zlib=0\r
80 -if pkg-config --exists zlib; then\r
81 +if pkg-config --atleast-version=1.2.5.2 zlib; then\r
82      printf "Yes.\n"\r
83      have_zlib=1\r
84      zlib_cflags=$(pkg-config --cflags zlib)\r
85 diff --git a/notmuch-dump.c b/notmuch-dump.c\r
86 index 05ed6b4..2a7252a 100644\r
87 --- a/notmuch-dump.c\r
88 +++ b/notmuch-dump.c\r
89 @@ -140,7 +140,7 @@ notmuch_database_dump (notmuch_database_t *notmuch,\r
90         tempname = talloc_asprintf (notmuch, "%s.XXXXXX", output_file_name);\r
91         outfd = mkstemp (tempname);\r
92      } else {\r
93 -       outfd = fileno (stdout);\r
94 +       outfd = dup (STDOUT_FILENO);\r
95      }\r
96  \r
97      if (outfd < 0) {\r
98 @@ -153,6 +153,9 @@ notmuch_database_dump (notmuch_database_t *notmuch,\r
99      if (output == NULL) {\r
100         fprintf (stderr, "Error opening %s for (gzip) writing: %s\n",\r
101                  name_for_error, strerror (errno));\r
102 +       if (close (outfd))\r
103 +           fprintf (stderr, "Error closing %s during shutdown: %s\n",\r
104 +                name_for_error, strerror (errno));\r
105         goto DONE;\r
106      }\r
107  \r
108 @@ -165,22 +168,25 @@ notmuch_database_dump (notmuch_database_t *notmuch,\r
109         goto DONE;\r
110      }\r
111  \r
112 -    ret = fdatasync (outfd);\r
113 -    if (ret) {\r
114 -       perror ("fdatasync");\r
115 -       goto DONE;\r
116 -    }\r
117 -\r
118      if (output_file_name) {\r
119 -       ret = gzclose_w (output);\r
120 -       if (ret != Z_OK) {\r
121 -           ret = EXIT_FAILURE;\r
122 +       ret = fdatasync (outfd);\r
123 +       if (ret) {\r
124 +           fprintf (stderr, "Error syncing %s to disk: %s\n",\r
125 +                    name_for_error, strerror (errno));\r
126             goto DONE;\r
127         }\r
128 +    }\r
129  \r
130 +    if (gzclose_w (output) != Z_OK) {\r
131 +       ret = EXIT_FAILURE;\r
132 +       goto DONE;\r
133 +    }\r
134 +\r
135 +    if (output_file_name) {\r
136         ret = rename (tempname, output_file_name);\r
137         if (ret) {\r
138 -           perror ("rename");\r
139 +           fprintf (stderr, "Error renaming %s to %s: %s\n",\r
140 +                    tempname, output_file_name, strerror (errno));\r
141             goto DONE;\r
142         }\r
143  \r
144 diff --git a/notmuch-new.c b/notmuch-new.c\r
145 index e0431c6..d269c7c 100644\r
146 --- a/notmuch-new.c\r
147 +++ b/notmuch-new.c\r
148 @@ -997,7 +997,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
149              * relatively small. */\r
150  \r
151             const char *backup_name =\r
152 -               talloc_asprintf (notmuch, "%s/backup-%04d-%02d-%02d-%02d:%02d:%02d.gz",\r
153 +               talloc_asprintf (notmuch, "%s/dump-%04d%02d%02dT%02d%02d%02d.gz",\r
154                                  dot_notmuch_path,\r
155                                  gm_time->tm_year + 1900,\r
156                                  gm_time->tm_mon + 1,\r
157 @@ -1009,12 +1009,12 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
158             if (add_files_state.verbosity >= VERBOSITY_NORMAL) {\r
159                 printf ("Welcome to a new version of notmuch! Your database will now be upgraded.\n");\r
160                 printf ("This process is safe to interrupt.\n");\r
161 -               printf ("Backing up tags to %s\n", backup_name);\r
162 +               printf ("Backing up tags to %s...\n", backup_name);\r
163             }\r
164  \r
165             if (notmuch_database_dump (notmuch, backup_name, "",\r
166                                        DUMP_FORMAT_BATCH_TAG, TRUE)) {\r
167 -               fprintf (stderr, "Backup failed. Aborting upgrade");\r
168 +               fprintf (stderr, "Backup failed. Aborting upgrade.");\r
169                 return EXIT_FAILURE;\r
170             }\r
171  \r
172 diff --git a/notmuch-restore.c b/notmuch-restore.c\r
173 index 86bce20..eb5b7b2 100644\r
174 --- a/notmuch-restore.c\r
175 +++ b/notmuch-restore.c\r
176 @@ -132,7 +132,6 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
177      gzFile input;\r
178      char *line = NULL;\r
179      void *line_ctx = NULL;\r
180 -    size_t line_size;\r
181      ssize_t line_len;\r
182  \r
183      int ret = 0;\r
184 @@ -166,8 +165,16 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
185  \r
186      if (input_file_name)\r
187         input = gzopen (input_file_name, "r");\r
188 -    else\r
189 -       input = gzdopen (fileno (stdin), "r");\r
190 +    else {\r
191 +       int infd = dup (STDIN_FILENO);\r
192 +       if (infd < 0) {\r
193 +           fprintf (stderr, "Error duping stdin\n");\r
194 +           return EXIT_FAILURE;\r
195 +       }\r
196 +       input = gzdopen (infd, "r");\r
197 +       if (! input)\r
198 +           close (infd);\r
199 +    }\r
200  \r
201      if (input == NULL) {\r
202         fprintf (stderr, "Error opening %s for (gzip) reading: %s\n",\r
203 @@ -189,7 +196,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
204      do {\r
205         util_status_t status;\r
206  \r
207 -       status = gz_getline (line_ctx, &line, &line_size, &line_len, input);\r
208 +       status = gz_getline (line_ctx, &line, &line_len, input);\r
209  \r
210         /* empty input file not considered an error */\r
211         if (status == UTIL_EOF)\r
212 @@ -262,7 +269,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
213         if (ret)\r
214             break;\r
215  \r
216 -    }  while (gz_getline (line_ctx, &line, &line_size, &line_len, input) == UTIL_SUCCESS);\r
217 +    }  while (gz_getline (line_ctx, &line, &line_len, input) == UTIL_SUCCESS);\r
218  \r
219      if (line_ctx != NULL)\r
220         talloc_free (line_ctx);\r
221 @@ -272,8 +279,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
222  \r
223      notmuch_database_destroy (notmuch);\r
224  \r
225 -    if (input_file_name != NULL)\r
226 -       gzclose_r (input);\r
227 +    gzclose_r (input);\r
228  \r
229      return ret ? EXIT_FAILURE : EXIT_SUCCESS;\r
230  }\r
231 diff --git a/test/T240-dump-restore.sh b/test/T240-dump-restore.sh\r
232 index 50d4d48..efe463e 100755\r
233 --- a/test/T240-dump-restore.sh\r
234 +++ b/test/T240-dump-restore.sh\r
235 @@ -124,6 +124,15 @@ notmuch dump --format=batch-tag from:cworth | sed 's/^.*-- id://' | \\r
236      sort > OUTPUT.$test_count\r
237  test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count\r
238  \r
239 +test_begin_subtest "format=batch-tag, missing newline"\r
240 +printf "+a_tag_without_newline -- id:20091117232137.GA7669@griffis1.net" > IN\r
241 +notmuch restore --accumulate < IN\r
242 +notmuch dump id:20091117232137.GA7669@griffis1.net > OUT\r
243 +cat <<EOF > EXPECTED\r
244 ++a_tag_without_newline +inbox +unread -- id:20091117232137.GA7669@griffis1.net\r
245 +EOF\r
246 +test_expect_equal_file EXPECTED OUT\r
247 +\r
248  test_begin_subtest "format=batch-tag, # round-trip"\r
249  notmuch dump --format=sup | sort > EXPECTED.$test_count\r
250  notmuch dump --format=batch-tag | notmuch restore --format=batch-tag\r
251 diff --git a/test/T530-upgrade.sh b/test/T530-upgrade.sh\r
252 index 7a68ddf..7d5d5aa 100755\r
253 --- a/test/T530-upgrade.sh\r
254 +++ b/test/T530-upgrade.sh\r
255 @@ -37,7 +37,7 @@ Your notmuch database has now been upgraded to database format version 2.\r
256  No new mail."\r
257  \r
258  test_begin_subtest "tag backup matches pre-upgrade dump"\r
259 -gunzip -c ${MAIL_DIR}/.notmuch/backup-*.gz | sort > backup-dump\r
260 +gunzip -c ${MAIL_DIR}/.notmuch/dump-*.gz | sort > backup-dump\r
261  test_expect_equal_file pre-upgrade-dump backup-dump\r
262  \r
263  test_begin_subtest "folder: no longer matches in the middle of path"\r
264 diff --git a/util/zlib-extra.c b/util/zlib-extra.c\r
265 index cb1eba0..922ab52 100644\r
266 --- a/util/zlib-extra.c\r
267 +++ b/util/zlib-extra.c\r
268 @@ -25,34 +25,36 @@\r
269  \r
270  /* mimic POSIX/glibc getline, but on a zlib gzFile stream, and using talloc */\r
271  util_status_t\r
272 -gz_getline (void *talloc_ctx, char **bufptr, size_t *bufsiz, ssize_t *bytes_read,\r
273 -           gzFile stream)\r
274 +gz_getline (void *talloc_ctx, char **bufptr, ssize_t *bytes_read, gzFile stream)\r
275  {\r
276 -    size_t len = *bufsiz;\r
277      char *buf = *bufptr;\r
278 +    unsigned int len;\r
279      size_t offset = 0;\r
280  \r
281 -    if (len == 0 || buf == NULL) {\r
282 +    if (buf) {\r
283 +       len = talloc_array_length (buf);\r
284 +    } else {\r
285         /* same as getdelim from gnulib */\r
286         len = 120;\r
287 -       buf = talloc_size (talloc_ctx, len);\r
288 +       buf = talloc_array (talloc_ctx, char, len);\r
289         if (buf == NULL)\r
290             return UTIL_OUT_OF_MEMORY;\r
291      }\r
292  \r
293      while (1) {\r
294         if (! gzgets (stream, buf + offset, len - offset)) {\r
295 +           /* Null indicates EOF or error */\r
296             int zlib_status = 0;\r
297             (void) gzerror (stream, &zlib_status);\r
298             switch (zlib_status) {\r
299             case Z_OK:\r
300 -               /* follow getline behaviour */\r
301 -               *bytes_read = -1;\r
302 -               return UTIL_EOF;\r
303 -               break;\r
304 +               /* no data read before EOF */\r
305 +               if (offset == 0)\r
306 +                   return UTIL_EOF;\r
307 +               else\r
308 +                   goto SUCCESS;\r
309             case Z_ERRNO:\r
310                 return UTIL_FILE;\r
311 -               break;\r
312             default:\r
313                 return UTIL_ERROR;\r
314             }\r
315 @@ -60,17 +62,16 @@ gz_getline (void *talloc_ctx, char **bufptr, size_t *bufsiz, ssize_t *bytes_read\r
316  \r
317         offset += strlen (buf + offset);\r
318  \r
319 -       if ( buf[offset - 1] == '\n' )\r
320 -           break;\r
321 +       if (buf[offset - 1] == '\n')\r
322 +           goto SUCCESS;\r
323  \r
324         len *= 2;\r
325         buf = talloc_realloc (talloc_ctx, buf, char, len);\r
326         if (buf == NULL)\r
327             return UTIL_OUT_OF_MEMORY;\r
328      }\r
329 -\r
330 + SUCCESS:\r
331      *bufptr = buf;\r
332 -    *bufsiz = len;\r
333      *bytes_read = offset;\r
334      return UTIL_SUCCESS;\r
335  }\r
336 diff --git a/util/zlib-extra.h b/util/zlib-extra.h\r
337 index ed46ac1..ed67115 100644\r
338 --- a/util/zlib-extra.h\r
339 +++ b/util/zlib-extra.h\r
340 @@ -1,11 +1,11 @@\r
341  #ifndef _ZLIB_EXTRA_H\r
342  #define _ZLIB_EXTRA_H\r
343  \r
344 -#include <zlib.h>\r
345  #include "util.h"\r
346 +#include <zlib.h>\r
347 +\r
348  /* Like getline, but read from a gzFile. Allocation is with talloc */\r
349  util_status_t\r
350 -gz_getline (void *ctx, char **lineptr, size_t *line_size, ssize_t *bytes_read,\r
351 -           gzFile stream);\r
352 +gz_getline (void *ctx, char **lineptr, ssize_t *bytes_read, gzFile stream);\r
353  \r
354  #endif\r