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 BCD24431FC9
\r
6 for <notmuch@notmuchmail.org>; Sat, 29 Mar 2014 11:16:59 -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 NX8JPB18EuIG for <notmuch@notmuchmail.org>;
\r
16 Sat, 29 Mar 2014 11:16:52 -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 37183431FBF
\r
21 for <notmuch@notmuchmail.org>; Sat, 29 Mar 2014 11:16:49 -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 1WTxoG-0007wj-V8; Sat, 29 Mar 2014 15:16:48 -0300
\r
25 Received: (nullmailer pid 29820 invoked by uid 1000); Sat, 29 Mar 2014
\r
27 From: David Bremner <david@tethera.net>
\r
28 To: notmuch@notmuchmail.org
\r
29 Subject: [Patch v2 3/3] restore: transparently support gzipped input
\r
30 Date: Sat, 29 Mar 2014 15:16:32 -0300
\r
31 Message-Id: <1396116992-29640-4-git-send-email-david@tethera.net>
\r
32 X-Mailer: git-send-email 1.9.0
\r
33 In-Reply-To: <1396116992-29640-1-git-send-email-david@tethera.net>
\r
34 References: <1396100785-8744-1-git-send-email-david@tethera.net>
\r
35 <1396116992-29640-1-git-send-email-david@tethera.net>
\r
36 X-BeenThere: notmuch@notmuchmail.org
\r
37 X-Mailman-Version: 2.1.13
\r
39 List-Id: "Use and development of the notmuch mail system."
\r
40 <notmuch.notmuchmail.org>
\r
41 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
42 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
44 List-Post: <mailto:notmuch@notmuchmail.org>
\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
46 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
47 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
48 X-List-Received-Date: Sat, 29 Mar 2014 18:17:00 -0000
\r
50 We rely completely on zlib to do the right thing in detecting gzipped
\r
51 input. Since our dump format is chosen to be 7 bit ascii, this should
\r
54 notmuch-restore.c | 30 +++++++++++++++---------------
\r
55 test/T240-dump-restore.sh | 14 ++++++++++++++
\r
56 2 files changed, 29 insertions(+), 15 deletions(-)
\r
58 diff --git a/notmuch-restore.c b/notmuch-restore.c
\r
59 index c54d513..50da480 100644
\r
60 --- a/notmuch-restore.c
\r
61 +++ b/notmuch-restore.c
\r
63 #include "hex-escape.h"
\r
64 #include "tag-util.h"
\r
65 #include "string-util.h"
\r
66 +#include "zlib-extra.h"
\r
68 static regex_t regex;
\r
70 @@ -128,7 +129,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
\r
71 tag_op_list_t *tag_ops;
\r
73 char *input_file_name = NULL;
\r
74 - FILE *input = stdin;
\r
77 void *line_ctx = NULL;
\r
79 @@ -163,13 +164,15 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
\r
81 flags |= TAG_FLAG_REMOVE_ALL;
\r
83 - if (input_file_name) {
\r
84 - input = fopen (input_file_name, "r");
\r
85 - if (input == NULL) {
\r
86 - fprintf (stderr, "Error opening %s for reading: %s\n",
\r
87 - input_file_name, strerror (errno));
\r
88 - return EXIT_FAILURE;
\r
90 + if (input_file_name)
\r
91 + input = gzopen (input_file_name, "r");
\r
93 + input = gzdopen (fileno (stdin), "r");
\r
95 + if (input == NULL) {
\r
96 + fprintf (stderr, "Error opening %s for (gzip) reading: %s\n",
\r
97 + input_file_name ? input_file_name : "stdin", strerror (errno));
\r
98 + return EXIT_FAILURE;
\r
101 if (opt_index < argc) {
\r
102 @@ -184,7 +187,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
\r
106 - line_len = getline (&line, &line_size, input);
\r
107 + line_len = gzgetline (line_ctx, &line, &line_size, input);
\r
109 /* empty input file not considered an error */
\r
111 @@ -254,7 +257,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
\r
115 - } while ((line_len = getline (&line, &line_size, input)) != -1);
\r
116 + } while ((line_len = gzgetline (line_ctx, &line, &line_size, input)) != -1);
\r
118 if (line_ctx != NULL)
\r
119 talloc_free (line_ctx);
\r
120 @@ -262,13 +265,10 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
\r
121 if (input_format == DUMP_FORMAT_SUP)
\r
127 notmuch_database_destroy (notmuch);
\r
129 - if (input != stdin)
\r
131 + if (input_file_name != NULL)
\r
132 + gzclose_r (input);
\r
134 return ret ? EXIT_FAILURE : EXIT_SUCCESS;
\r
136 diff --git a/test/T240-dump-restore.sh b/test/T240-dump-restore.sh
\r
137 index d79aca8..50d4d48 100755
\r
138 --- a/test/T240-dump-restore.sh
\r
139 +++ b/test/T240-dump-restore.sh
\r
140 @@ -80,6 +80,20 @@ notmuch dump --gzip --output=dump-gzip-outfile.gz
\r
141 gunzip dump-gzip-outfile.gz
\r
142 test_expect_equal_file dump.expected dump-gzip-outfile
\r
144 +test_begin_subtest "restoring gzipped stdin"
\r
145 +notmuch dump --gzip --output=backup.gz
\r
146 +notmuch tag +new_tag '*'
\r
147 +notmuch restore < backup.gz
\r
148 +notmuch dump --output=dump.actual
\r
149 +test_expect_equal_file dump.expected dump.actual
\r
151 +test_begin_subtest "restoring gzipped file"
\r
152 +notmuch dump --gzip --output=backup.gz
\r
153 +notmuch tag +new_tag '*'
\r
154 +notmuch restore --input=backup.gz
\r
155 +notmuch dump --output=dump.actual
\r
156 +test_expect_equal_file dump.expected dump.actual
\r
158 # Note, we assume all messages from cworth have a message-id
\r
159 # containing cworth.org
\r