[PATCH 0/6] Use notmuch insert for fcc
[notmuch-archives.git] / 00 / 44ca8b46f3cdc54d53a11a1075a3c78935d9da
1 Return-Path: <amdragon@mit.edu>\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 16B52431FBF\r
6         for <notmuch@notmuchmail.org>; Tue,  1 Apr 2014 19:49:52 -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.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 Oxu4OOMTlZ+0 for <notmuch@notmuchmail.org>;\r
16         Tue,  1 Apr 2014 19:49:44 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-1.mit.edu (dmz-mailsec-scanner-1.mit.edu\r
18         [18.9.25.12])\r
19         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id A9B5C431FBD\r
22         for <notmuch@notmuchmail.org>; Tue,  1 Apr 2014 19:49:43 -0700 (PDT)\r
23 X-AuditID: 1209190c-f794a6d000000c27-c9-533b7ac5e591\r
24 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
25         (using TLS with cipher AES256-SHA (256/256 bits))\r
26         (Client did not present a certificate)\r
27         by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
28         id C8.93.03111.5CA7B335; Tue,  1 Apr 2014 22:49:41 -0400 (EDT)\r
29 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
30         by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id s322nedP017188; \r
31         Tue, 1 Apr 2014 22:49:41 -0400\r
32 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
33         (authenticated bits=0)\r
34         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
35         by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s322ncZu028902\r
36         (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT);\r
37         Tue, 1 Apr 2014 22:49:40 -0400\r
38 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80)\r
39         (envelope-from <amdragon@mit.edu>)\r
40         id 1WVBFC-0004Ib-M1; Tue, 01 Apr 2014 22:49:38 -0400\r
41 Date: Tue, 1 Apr 2014 22:49:38 -0400\r
42 From: Austin Clements <amdragon@MIT.EDU>\r
43 To: David Bremner <david@tethera.net>\r
44 Subject: Re: [Patch v5 4/6] restore: transparently support gzipped input\r
45 Message-ID: <20140402024938.GA25677@mit.edu>\r
46 References: <1396401381-18128-1-git-send-email-david@tethera.net>\r
47         <1396401381-18128-5-git-send-email-david@tethera.net>\r
48 MIME-Version: 1.0\r
49 Content-Type: text/plain; charset=us-ascii\r
50 Content-Disposition: inline\r
51 In-Reply-To: <1396401381-18128-5-git-send-email-david@tethera.net>\r
52 User-Agent: Mutt/1.5.21 (2010-09-15)\r
53 X-Brightmail-Tracker:\r
54  H4sIAAAAAAAAA+NgFmpileLIzCtJLcpLzFFi42IR4hTV1j1aZR1sMOOzhsWN1m5Gi+s3ZzI7\r
55         MHk8W3WL2WPLoffMAUxRXDYpqTmZZalF+nYJXBmrTp1lLziqXjH7bWUD43W5LkZODgkBE4lv\r
56         e/6wQNhiEhfurWfrYuTiEBKYzSQx8+w2dghnA6NEy7WJrBDOKSaJZa+7GCGcJYwSmxf0MIH0\r
57         swioSHydtYsZxGYT0JDYtn85I4gtIqAqcXXbZDYQm1lAWuLb72awemEBD4lt25aD7eYV0JGY\r
58         t+s0UA0H0NBKiUcXZSHCghInZz5hgWjVkrjx7yUTSAnImOX/OEDCnAJOEudWrmUHsUWBLphy\r
59         chvbBEahWUi6ZyHpnoXQvYCReRWjbEpulW5uYmZOcWqybnFyYl5eapGuoV5uZoleakrpJkZw\r
60         UEvy7GB8c1DpEKMAB6MSD++B81bBQqyJZcWVuYcYJTmYlER5OYKtg4X4kvJTKjMSizPii0pz\r
61         UosPMUpwMCuJ8H73BcrxpiRWVqUW5cOkpDlYlMR531oDTRJITyxJzU5NLUgtgsnKcHAoSfBO\r
62         rQRqFCxKTU+tSMvMKUFIM3FwggznARqeC1LDW1yQmFucmQ6RP8WoKCXOuwQkIQCSyCjNg+uF\r
63         JZ1XjOJArwjzfgep4gEmLLjuV0CDmYAGc6+zAhlckoiQkmpgrGmMecNWrfjNPcHLviriXWJ5\r
64         3JzCExKzZqpO+X7z8iFJxTOcQuteMxXEhDFdqshfZFOgq6Ptr7A7q8i222DvPrZXaZ1TG/R8\r
65         9n9iz2qvqM38W6+S5pyWoib0kyU5+36QqOjKkrbImM2358rpT27ZU8nyNeLHsi9vD18+/OGQ\r
66         arKwftcujv1KLMUZiYZazEXFiQAImOYMFQMAAA==\r
67 Cc: notmuch@notmuchmail.org\r
68 X-BeenThere: notmuch@notmuchmail.org\r
69 X-Mailman-Version: 2.1.13\r
70 Precedence: list\r
71 List-Id: "Use and development of the notmuch mail system."\r
72         <notmuch.notmuchmail.org>\r
73 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
74         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
75 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
76 List-Post: <mailto:notmuch@notmuchmail.org>\r
77 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
78 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
79         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
80 X-List-Received-Date: Wed, 02 Apr 2014 02:49:52 -0000\r
81 \r
82 Quoth David Bremner on Apr 01 at 10:16 pm:\r
83 > We rely completely on zlib to do the right thing in detecting gzipped\r
84 > input. Since our dump format is chosen to be 7 bit ascii, this should\r
85 > be fine.\r
86 > ---\r
87 >  doc/man1/notmuch-restore.rst |  8 ++++++++\r
88 >  notmuch-restore.c            | 37 +++++++++++++++++++++----------------\r
89 >  test/T240-dump-restore.sh    | 14 ++++++++++++++\r
90 >  3 files changed, 43 insertions(+), 16 deletions(-)\r
91\r
92 > diff --git a/doc/man1/notmuch-restore.rst b/doc/man1/notmuch-restore.rst\r
93 > index d6cf19a..936b138 100644\r
94 > --- a/doc/man1/notmuch-restore.rst\r
95 > +++ b/doc/man1/notmuch-restore.rst\r
96 > @@ -50,6 +50,14 @@ Supported options for **restore** include\r
97 >              format, this heuristic, based the fact that batch-tag format\r
98 >              contains no parentheses, should be accurate.\r
99 >  \r
100 > +GZIPPED INPUT\r
101 > +=============\r
102 > +\r
103 > +\ **notmuch restore** will detect if the input is compressed in\r
104 > +**gzip(1)** format and automatically decompress it while reading. This\r
105 > +detection does not depend on file naming and in particular works for\r
106 > +standard input.\r
107 > +\r
108 >  SEE ALSO\r
109 >  ========\r
110 >  \r
111 > diff --git a/notmuch-restore.c b/notmuch-restore.c\r
112 > index c54d513..86bce20 100644\r
113 > --- a/notmuch-restore.c\r
114 > +++ b/notmuch-restore.c\r
115 > @@ -22,6 +22,7 @@\r
116 >  #include "hex-escape.h"\r
117 >  #include "tag-util.h"\r
118 >  #include "string-util.h"\r
119 > +#include "zlib-extra.h"\r
120 >  \r
121 >  static regex_t regex;\r
122 >  \r
123 > @@ -128,7 +129,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
124 >      tag_op_list_t *tag_ops;\r
125 >  \r
126 >      char *input_file_name = NULL;\r
127 > -    FILE *input = stdin;\r
128 > +    gzFile input;\r
129 >      char *line = NULL;\r
130 >      void *line_ctx = NULL;\r
131 >      size_t line_size;\r
132 > @@ -163,13 +164,15 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
133 >      if (! accumulate)\r
134 >       flags |= TAG_FLAG_REMOVE_ALL;\r
135 >  \r
136 > -    if (input_file_name) {\r
137 > -     input = fopen (input_file_name, "r");\r
138 > -     if (input == NULL) {\r
139 > -         fprintf (stderr, "Error opening %s for reading: %s\n",\r
140 > -                  input_file_name, strerror (errno));\r
141 > -         return EXIT_FAILURE;\r
142 > -     }\r
143 > +    if (input_file_name)\r
144 > +     input = gzopen (input_file_name, "r");\r
145 > +    else\r
146 > +     input = gzdopen (fileno (stdin), "r");\r
147 \r
148 As for patch 2, we also need to gzclose input on all paths out of this\r
149 function, which also means we probably need to dup stdin above.\r
150 \r
151 > +\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 >      }\r
157 >  \r
158 >      if (opt_index < argc) {\r
159 > @@ -184,12 +187,17 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
160 >      }\r
161 >  \r
162 >      do {\r
163 > -     line_len = getline (&line, &line_size, input);\r
164 > +     util_status_t status;\r
165 > +\r
166 > +     status = gz_getline (line_ctx, &line, &line_size, &line_len, input);\r
167 >  \r
168 >       /* empty input file not considered an error */\r
169 > -     if (line_len < 0)\r
170 > +     if (status == UTIL_EOF)\r
171 >           return EXIT_SUCCESS;\r
172 >  \r
173 > +     if (status)\r
174 > +         return EXIT_FAILURE;\r
175 > +\r
176 >      } while ((line_len == 0) ||\r
177 >            (line[0] == '#') ||\r
178 >            /* the cast is safe because we checked about for line_len < 0 */\r
179 > @@ -254,7 +262,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
180 >       if (ret)\r
181 >           break;\r
182 >  \r
183 > -    }  while ((line_len = getline (&line, &line_size, input)) != -1);\r
184 > +    }  while (gz_getline (line_ctx, &line, &line_size, &line_len, input) == UTIL_SUCCESS);\r
185 >  \r
186 >      if (line_ctx != NULL)\r
187 >       talloc_free (line_ctx);\r
188 > @@ -262,13 +270,10 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
189 >      if (input_format == DUMP_FORMAT_SUP)\r
190 >       regfree (&regex);\r
191 >  \r
192 > -    if (line)\r
193 > -     free (line);\r
194 > -\r
195 >      notmuch_database_destroy (notmuch);\r
196 >  \r
197 > -    if (input != stdin)\r
198 > -     fclose (input);\r
199 > +    if (input_file_name != NULL)\r
200 > +     gzclose_r (input);\r
201 >  \r
202 >      return ret ? EXIT_FAILURE : EXIT_SUCCESS;\r
203 >  }\r
204 > diff --git a/test/T240-dump-restore.sh b/test/T240-dump-restore.sh\r
205 > index d79aca8..50d4d48 100755\r
206 > --- a/test/T240-dump-restore.sh\r
207 > +++ b/test/T240-dump-restore.sh\r
208 > @@ -80,6 +80,20 @@ notmuch dump --gzip --output=dump-gzip-outfile.gz\r
209 >  gunzip dump-gzip-outfile.gz\r
210 >  test_expect_equal_file dump.expected dump-gzip-outfile\r
211 >  \r
212 > +test_begin_subtest "restoring gzipped stdin"\r
213 > +notmuch dump --gzip --output=backup.gz\r
214 > +notmuch tag +new_tag '*'\r
215 > +notmuch restore < backup.gz\r
216 > +notmuch dump --output=dump.actual\r
217 > +test_expect_equal_file dump.expected dump.actual\r
218 > +\r
219 > +test_begin_subtest "restoring gzipped file"\r
220 > +notmuch dump --gzip --output=backup.gz\r
221 > +notmuch tag +new_tag '*'\r
222 > +notmuch restore --input=backup.gz\r
223 > +notmuch dump --output=dump.actual\r
224 > +test_expect_equal_file dump.expected dump.actual\r
225 > +\r
226 >  # Note, we assume all messages from cworth have a message-id\r
227 >  # containing cworth.org\r
228 >  \r