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 49EF4431FBC
\r
6 for <notmuch@notmuchmail.org>; Fri, 28 Mar 2014 18:21:07 -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 156cfDDvftAf for <notmuch@notmuchmail.org>;
\r
16 Fri, 28 Mar 2014 18:21:01 -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 C4DC3431FAF
\r
21 for <notmuch@notmuchmail.org>; Fri, 28 Mar 2014 18:21:01 -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 1WThx9-0004XZ-MW; Fri, 28 Mar 2014 22:20:55 -0300
\r
25 Received: (nullmailer pid 2727 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] RFC: impliment gzipped output for notmuch dump
\r
30 Date: Fri, 28 Mar 2014 22:20:46 -0300
\r
31 Message-Id: <1396056046-2247-1-git-send-email-david@tethera.net>
\r
32 X-Mailer: git-send-email 1.9.0
\r
33 In-Reply-To: <874n2kipq4.fsf@qmul.ac.uk>
\r
34 References: <874n2kipq4.fsf@qmul.ac.uk>
\r
35 X-BeenThere: notmuch@notmuchmail.org
\r
36 X-Mailman-Version: 2.1.13
\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: Sat, 29 Mar 2014 01:21:07 -0000
\r
51 This obviously needs at least one piece of tidying, and some tests.
\r
53 My motivation here is the ability to make gzipped backups from within
\r
54 notmuch, e.g. as part of an upgrade procedure.
\r
57 Makefile.local | 2 +-
\r
58 configure | 19 ++++++++++++++++++-
\r
59 notmuch-client.h | 4 +++-
\r
60 notmuch-dump.c | 41 +++++++++++++++++++++++++++--------------
\r
61 4 files changed, 49 insertions(+), 17 deletions(-)
\r
63 diff --git a/Makefile.local b/Makefile.local
\r
64 index cb7b106..e5a20a7 100644
\r
65 --- a/Makefile.local
\r
66 +++ b/Makefile.local
\r
67 @@ -41,7 +41,7 @@ PV_FILE=bindings/python/notmuch/version.py
\r
68 # Smash together user's values with our extra values
\r
69 FINAL_CFLAGS = -DNOTMUCH_VERSION=$(VERSION) $(CPPFLAGS) $(CFLAGS) $(WARN_CFLAGS) $(extra_cflags) $(CONFIGURE_CFLAGS)
\r
70 FINAL_CXXFLAGS = $(CPPFLAGS) $(CXXFLAGS) $(WARN_CXXFLAGS) $(extra_cflags) $(extra_cxxflags) $(CONFIGURE_CXXFLAGS)
\r
71 -FINAL_NOTMUCH_LDFLAGS = $(LDFLAGS) -Lutil -lutil -Llib -lnotmuch $(AS_NEEDED_LDFLAGS) $(GMIME_LDFLAGS) $(TALLOC_LDFLAGS)
\r
72 +FINAL_NOTMUCH_LDFLAGS = $(LDFLAGS) -Lutil -lutil -Llib -lnotmuch $(AS_NEEDED_LDFLAGS) $(GMIME_LDFLAGS) $(TALLOC_LDFLAGS) $(ZLIB_LDFLAGS)
\r
73 FINAL_NOTMUCH_LINKER = CC
\r
74 ifneq ($(LINKER_RESOLVES_LIBRARY_DEPENDENCIES),1)
\r
75 FINAL_NOTMUCH_LDFLAGS += $(CONFIGURE_LDFLAGS)
\r
76 diff --git a/configure b/configure
\r
77 index 1d430b9..02ef785 100755
\r
80 @@ -340,6 +340,18 @@ else
\r
81 errors=$((errors + 1))
\r
84 +printf "Checking for zlib development files... "
\r
86 +if pkg-config --exists zlib; then
\r
89 + zlib_cflags=$(pkg-config --cflags zlib)
\r
90 + zlib_ldflags=$(pkg-config --libs zlib)
\r
93 + errors=$((errors + 1))
\r
96 printf "Checking for talloc development files... "
\r
97 if pkg-config --exists talloc; then
\r
99 @@ -844,6 +856,10 @@ XAPIAN_LDFLAGS = ${xapian_ldflags}
\r
100 GMIME_CFLAGS = ${gmime_cflags}
\r
101 GMIME_LDFLAGS = ${gmime_ldflags}
\r
103 +# Flags needed to compile and link against zlib
\r
104 +ZLIB_CFLAGS = ${zlib_cflags}
\r
105 +ZLIB_LDFLAGS = ${zlib_ldflags}
\r
107 # Flags needed to compile and link against talloc
\r
108 TALLOC_CFLAGS = ${talloc_cflags}
\r
109 TALLOC_LDFLAGS = ${talloc_ldflags}
\r
110 @@ -882,6 +898,7 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\r
111 -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)
\r
113 CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\r
114 + \$(ZLIB_CFLAGS) \\
\r
115 \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
\r
116 \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS) \\
\r
117 -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR) \\
\r
118 @@ -892,5 +909,5 @@ CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\r
119 -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT) \\
\r
120 -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)
\r
122 -CONFIGURE_LDFLAGS = \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)
\r
123 +CONFIGURE_LDFLAGS = \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(ZLIB_LDFLAGS) \$(XAPIAN_LDFLAGS)
\r
125 diff --git a/notmuch-client.h b/notmuch-client.h
\r
126 index d110648..e1efbe0 100644
\r
127 --- a/notmuch-client.h
\r
128 +++ b/notmuch-client.h
\r
129 @@ -450,7 +450,9 @@ typedef enum dump_formats {
\r
131 notmuch_database_dump (notmuch_database_t *notmuch,
\r
132 const char *output_file_name,
\r
133 - const char *query_str, dump_format_t output_format);
\r
134 + const char *query_str,
\r
135 + dump_format_t output_format,
\r
136 + notmuch_bool_t gzip_output);
\r
138 #include "command-line-arguments.h"
\r
140 diff --git a/notmuch-dump.c b/notmuch-dump.c
\r
141 index 21702d7..029f90a 100644
\r
142 --- a/notmuch-dump.c
\r
143 +++ b/notmuch-dump.c
\r
144 @@ -21,10 +21,12 @@
\r
145 #include "notmuch-client.h"
\r
146 #include "hex-escape.h"
\r
147 #include "string-util.h"
\r
152 -database_dump_file (notmuch_database_t *notmuch, FILE *output,
\r
153 - const char *query_str, int output_format)
\r
154 +database_dump_file (notmuch_database_t *notmuch, gzFile output,
\r
155 + const char *query_str, int output_format)
\r
157 notmuch_query_t *query;
\r
158 notmuch_messages_t *messages;
\r
159 @@ -69,7 +71,7 @@ database_dump_file (notmuch_database_t *notmuch, FILE *output,
\r
162 if (output_format == DUMP_FORMAT_SUP) {
\r
163 - fprintf (output, "%s (", message_id);
\r
164 + gzprintf (output, "%s (", message_id);
\r
167 for (tags = notmuch_message_get_tags (message);
\r
168 @@ -78,12 +80,12 @@ database_dump_file (notmuch_database_t *notmuch, FILE *output,
\r
169 const char *tag_str = notmuch_tags_get (tags);
\r
172 - fputs (" ", output);
\r
173 + gzputs (output, " ");
\r
177 if (output_format == DUMP_FORMAT_SUP) {
\r
178 - fputs (tag_str, output);
\r
179 + gzputs (output, tag_str);
\r
181 if (hex_encode (notmuch, tag_str,
\r
182 &buffer, &buffer_size) != HEX_SUCCESS) {
\r
183 @@ -91,12 +93,12 @@ database_dump_file (notmuch_database_t *notmuch, FILE *output,
\r
185 return EXIT_FAILURE;
\r
187 - fprintf (output, "+%s", buffer);
\r
188 + gzprintf (output, "+%s", buffer);
\r
192 if (output_format == DUMP_FORMAT_SUP) {
\r
193 - fputs (")\n", output);
\r
194 + gzputs (output, ")\n");
\r
196 if (make_boolean_term (notmuch, "id", message_id,
\r
197 &buffer, &buffer_size)) {
\r
198 @@ -104,7 +106,7 @@ database_dump_file (notmuch_database_t *notmuch, FILE *output,
\r
199 message_id, strerror (errno));
\r
200 return EXIT_FAILURE;
\r
202 - fprintf (output, " -- %s\n", buffer);
\r
203 + gzprintf (output, " -- %s\n", buffer);
\r
206 notmuch_message_destroy (message);
\r
207 @@ -121,24 +123,33 @@ database_dump_file (notmuch_database_t *notmuch, FILE *output,
\r
209 notmuch_database_dump (notmuch_database_t *notmuch,
\r
210 const char *output_file_name,
\r
211 - const char *query_str, dump_format_t output_format)
\r
212 + const char *query_str,
\r
213 + dump_format_t output_format,
\r
214 + notmuch_bool_t gzip_output)
\r
216 - FILE *output = stdout;
\r
218 + const char *mode = gzip_output ? "w9" : "wT";
\r
222 if (output_file_name) {
\r
223 - output = fopen (output_file_name, "w");
\r
224 + output = gzopen (output_file_name, mode);
\r
225 if (output == NULL) {
\r
226 fprintf (stderr, "Error opening %s for writing: %s\n",
\r
227 output_file_name, strerror (errno));
\r
228 return EXIT_FAILURE;
\r
231 + output = gzdopen (fileno (stdout), mode);
\r
234 ret = database_dump_file (notmuch, output, query_str, output_format);
\r
236 - if (output != stdout)
\r
238 + /* XXX check error return */
\r
239 + gzflush (output, Z_FINISH);
\r
241 + if (output_file_name)
\r
242 + gzclose_w (output);
\r
246 @@ -158,6 +169,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
249 int output_format = DUMP_FORMAT_BATCH_TAG;
\r
250 + notmuch_bool_t gzip_output = 0;
\r
252 notmuch_opt_desc_t options[] = {
\r
253 { NOTMUCH_OPT_KEYWORD, &output_format, "format", 'f',
\r
254 @@ -165,6 +177,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
255 { "batch-tag", DUMP_FORMAT_BATCH_TAG },
\r
257 { NOTMUCH_OPT_STRING, &output_file_name, "output", 'o', 0 },
\r
258 + { NOTMUCH_OPT_BOOLEAN, &gzip_output, "gzip", 'z', 0 },
\r
262 @@ -181,7 +194,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
265 ret = notmuch_database_dump (notmuch, output_file_name, query_str,
\r
267 + output_format, gzip_output);
\r
269 notmuch_database_destroy (notmuch);
\r