Re: [PATCH] Fix typo in Message.maildir_flags_to_tags
[notmuch-archives.git] / fa / a5768031620a6fbb8e4a431e31f511ef922732
1 Return-Path: <bremner@tethera.net>\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 220B4431FD4\r
6         for <notmuch@notmuchmail.org>; Sun, 30 Mar 2014 10:32:08 -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 jcDcJzFGCjMe for <notmuch@notmuchmail.org>;\r
16         Sun, 30 Mar 2014 10:32:00 -0700 (PDT)\r
17 Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
18         (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 3A859431FBF\r
21         for <notmuch@notmuchmail.org>; Sun, 30 Mar 2014 10:31:58 -0700 (PDT)\r
22 Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
23         (envelope-from <bremner@tethera.net>)\r
24         id 1WUJaP-0004Av-Tx; Sun, 30 Mar 2014 14:31:57 -0300\r
25 Received: (nullmailer pid 29606 invoked by uid 1000); Sun, 30 Mar 2014\r
26         17:31:43 -0000\r
27 From: David Bremner <david@tethera.net>\r
28 To: notmuch@notmuchmail.org\r
29 Subject: [Patch v4 3/3] restore: transparently support gzipped input\r
30 Date: Sun, 30 Mar 2014 14:31:40 -0300\r
31 Message-Id: <1396200700-29361-4-git-send-email-david@tethera.net>\r
32 X-Mailer: git-send-email 1.9.0\r
33 In-Reply-To: <1396200700-29361-1-git-send-email-david@tethera.net>\r
34 References: <1396200700-29361-1-git-send-email-david@tethera.net>\r
35 X-BeenThere: notmuch@notmuchmail.org\r
36 X-Mailman-Version: 2.1.13\r
37 Precedence: list\r
38 List-Id: "Use and development of the notmuch mail system."\r
39         <notmuch.notmuchmail.org>\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
43 List-Post: <mailto:notmuch@notmuchmail.org>\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
47 X-List-Received-Date: Sun, 30 Mar 2014 17:32:08 -0000\r
48 \r
49 We rely completely on zlib to do the right thing in detecting gzipped\r
50 input. Since our dump format is chosen to be 7 bit ascii, this should\r
51 be fine.\r
52 ---\r
53  notmuch-restore.c         | 37 +++++++++++++++++++++----------------\r
54  test/T240-dump-restore.sh | 14 ++++++++++++++\r
55  2 files changed, 35 insertions(+), 16 deletions(-)\r
56 \r
57 diff --git a/notmuch-restore.c b/notmuch-restore.c\r
58 index c54d513..86bce20 100644\r
59 --- a/notmuch-restore.c\r
60 +++ b/notmuch-restore.c\r
61 @@ -22,6 +22,7 @@\r
62  #include "hex-escape.h"\r
63  #include "tag-util.h"\r
64  #include "string-util.h"\r
65 +#include "zlib-extra.h"\r
66  \r
67  static regex_t regex;\r
68  \r
69 @@ -128,7 +129,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
70      tag_op_list_t *tag_ops;\r
71  \r
72      char *input_file_name = NULL;\r
73 -    FILE *input = stdin;\r
74 +    gzFile input;\r
75      char *line = NULL;\r
76      void *line_ctx = NULL;\r
77      size_t line_size;\r
78 @@ -163,13 +164,15 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
79      if (! accumulate)\r
80         flags |= TAG_FLAG_REMOVE_ALL;\r
81  \r
82 -    if (input_file_name) {\r
83 -       input = fopen (input_file_name, "r");\r
84 -       if (input == NULL) {\r
85 -           fprintf (stderr, "Error opening %s for reading: %s\n",\r
86 -                    input_file_name, strerror (errno));\r
87 -           return EXIT_FAILURE;\r
88 -       }\r
89 +    if (input_file_name)\r
90 +       input = gzopen (input_file_name, "r");\r
91 +    else\r
92 +       input = gzdopen (fileno (stdin), "r");\r
93 +\r
94 +    if (input == NULL) {\r
95 +       fprintf (stderr, "Error opening %s for (gzip) reading: %s\n",\r
96 +                input_file_name ? input_file_name : "stdin", strerror (errno));\r
97 +       return EXIT_FAILURE;\r
98      }\r
99  \r
100      if (opt_index < argc) {\r
101 @@ -184,12 +187,17 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
102      }\r
103  \r
104      do {\r
105 -       line_len = getline (&line, &line_size, input);\r
106 +       util_status_t status;\r
107 +\r
108 +       status = gz_getline (line_ctx, &line, &line_size, &line_len, input);\r
109  \r
110         /* empty input file not considered an error */\r
111 -       if (line_len < 0)\r
112 +       if (status == UTIL_EOF)\r
113             return EXIT_SUCCESS;\r
114  \r
115 +       if (status)\r
116 +           return EXIT_FAILURE;\r
117 +\r
118      } while ((line_len == 0) ||\r
119              (line[0] == '#') ||\r
120              /* the cast is safe because we checked about for line_len < 0 */\r
121 @@ -254,7 +262,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
122         if (ret)\r
123             break;\r
124  \r
125 -    }  while ((line_len = getline (&line, &line_size, input)) != -1);\r
126 +    }  while (gz_getline (line_ctx, &line, &line_size, &line_len, input) == UTIL_SUCCESS);\r
127  \r
128      if (line_ctx != NULL)\r
129         talloc_free (line_ctx);\r
130 @@ -262,13 +270,10 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
131      if (input_format == DUMP_FORMAT_SUP)\r
132         regfree (&regex);\r
133  \r
134 -    if (line)\r
135 -       free (line);\r
136 -\r
137      notmuch_database_destroy (notmuch);\r
138  \r
139 -    if (input != stdin)\r
140 -       fclose (input);\r
141 +    if (input_file_name != NULL)\r
142 +       gzclose_r (input);\r
143  \r
144      return ret ? EXIT_FAILURE : EXIT_SUCCESS;\r
145  }\r
146 diff --git a/test/T240-dump-restore.sh b/test/T240-dump-restore.sh\r
147 index d79aca8..50d4d48 100755\r
148 --- a/test/T240-dump-restore.sh\r
149 +++ b/test/T240-dump-restore.sh\r
150 @@ -80,6 +80,20 @@ notmuch dump --gzip --output=dump-gzip-outfile.gz\r
151  gunzip dump-gzip-outfile.gz\r
152  test_expect_equal_file dump.expected dump-gzip-outfile\r
153  \r
154 +test_begin_subtest "restoring gzipped stdin"\r
155 +notmuch dump --gzip --output=backup.gz\r
156 +notmuch tag +new_tag '*'\r
157 +notmuch restore < backup.gz\r
158 +notmuch dump --output=dump.actual\r
159 +test_expect_equal_file dump.expected dump.actual\r
160 +\r
161 +test_begin_subtest "restoring gzipped file"\r
162 +notmuch dump --gzip --output=backup.gz\r
163 +notmuch tag +new_tag '*'\r
164 +notmuch restore --input=backup.gz\r
165 +notmuch dump --output=dump.actual\r
166 +test_expect_equal_file dump.expected dump.actual\r
167 +\r
168  # Note, we assume all messages from cworth have a message-id\r
169  # containing cworth.org\r
170  \r
171 -- \r
172 1.9.0\r
173 \r