1 Return-Path: <tomi.ollila@iki.fi>
\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 19317431FBF
\r
6 for <notmuch@notmuchmail.org>; Sat, 29 Mar 2014 00:16:21 -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 AfuJms+9iLHJ for <notmuch@notmuchmail.org>;
\r
16 Sat, 29 Mar 2014 00:16:17 -0700 (PDT)
\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 6FAEA431FBC
\r
19 for <notmuch@notmuchmail.org>; Sat, 29 Mar 2014 00:16:17 -0700 (PDT)
\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])
\r
21 by guru.guru-group.fi (Postfix) with ESMTP id C169E1000E5;
\r
22 Sat, 29 Mar 2014 09:16:11 +0200 (EET)
\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
24 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
\r
25 Subject: Re: [PATCH] RFC: impliment gzipped output for notmuch dump
\r
26 In-Reply-To: <1396056046-2247-1-git-send-email-david@tethera.net>
\r
27 References: <874n2kipq4.fsf@qmul.ac.uk>
\r
28 <1396056046-2247-1-git-send-email-david@tethera.net>
\r
29 User-Agent: Notmuch/0.17+159~gb806a13 (http://notmuchmail.org) Emacs/24.3.1
\r
30 (x86_64-unknown-linux-gnu)
\r
31 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL
\r
32 $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F
\r
33 !)g;OY^,BjTbr)Np:%c_o'jj,Z
\r
34 Date: Sat, 29 Mar 2014 09:16:11 +0200
\r
35 Message-ID: <m2siq11nlw.fsf@guru.guru-group.fi>
\r
37 Content-Type: text/plain
\r
38 X-BeenThere: notmuch@notmuchmail.org
\r
39 X-Mailman-Version: 2.1.13
\r
41 List-Id: "Use and development of the notmuch mail system."
\r
42 <notmuch.notmuchmail.org>
\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
46 List-Post: <mailto:notmuch@notmuchmail.org>
\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
50 X-List-Received-Date: Sat, 29 Mar 2014 07:16:21 -0000
\r
52 On Sat, Mar 29 2014, David Bremner <david@tethera.net> wrote:
\r
56 > This obviously needs at least one piece of tidying, and some tests.
\r
58 > My motivation here is the ability to make gzipped backups from within
\r
59 > notmuch, e.g. as part of an upgrade procedure.
\r
65 > Makefile.local | 2 +-
\r
66 > configure | 19 ++++++++++++++++++-
\r
67 > notmuch-client.h | 4 +++-
\r
68 > notmuch-dump.c | 41 +++++++++++++++++++++++++++--------------
\r
69 > 4 files changed, 49 insertions(+), 17 deletions(-)
\r
71 > diff --git a/Makefile.local b/Makefile.local
\r
72 > index cb7b106..e5a20a7 100644
\r
73 > --- a/Makefile.local
\r
74 > +++ b/Makefile.local
\r
75 > @@ -41,7 +41,7 @@ PV_FILE=bindings/python/notmuch/version.py
\r
76 > # Smash together user's values with our extra values
\r
77 > FINAL_CFLAGS = -DNOTMUCH_VERSION=$(VERSION) $(CPPFLAGS) $(CFLAGS) $(WARN_CFLAGS) $(extra_cflags) $(CONFIGURE_CFLAGS)
\r
78 > FINAL_CXXFLAGS = $(CPPFLAGS) $(CXXFLAGS) $(WARN_CXXFLAGS) $(extra_cflags) $(extra_cxxflags) $(CONFIGURE_CXXFLAGS)
\r
79 > -FINAL_NOTMUCH_LDFLAGS = $(LDFLAGS) -Lutil -lutil -Llib -lnotmuch $(AS_NEEDED_LDFLAGS) $(GMIME_LDFLAGS) $(TALLOC_LDFLAGS)
\r
80 > +FINAL_NOTMUCH_LDFLAGS = $(LDFLAGS) -Lutil -lutil -Llib -lnotmuch $(AS_NEEDED_LDFLAGS) $(GMIME_LDFLAGS) $(TALLOC_LDFLAGS) $(ZLIB_LDFLAGS)
\r
81 > FINAL_NOTMUCH_LINKER = CC
\r
82 > ifneq ($(LINKER_RESOLVES_LIBRARY_DEPENDENCIES),1)
\r
83 > FINAL_NOTMUCH_LDFLAGS += $(CONFIGURE_LDFLAGS)
\r
84 > diff --git a/configure b/configure
\r
85 > index 1d430b9..02ef785 100755
\r
88 > @@ -340,6 +340,18 @@ else
\r
89 > errors=$((errors + 1))
\r
92 > +printf "Checking for zlib development files... "
\r
94 > +if pkg-config --exists zlib; then
\r
97 > + zlib_cflags=$(pkg-config --cflags zlib)
\r
98 > + zlib_ldflags=$(pkg-config --libs zlib)
\r
101 > + errors=$((errors + 1))
\r
104 > printf "Checking for talloc development files... "
\r
105 > if pkg-config --exists talloc; then
\r
107 > @@ -844,6 +856,10 @@ XAPIAN_LDFLAGS = ${xapian_ldflags}
\r
108 > GMIME_CFLAGS = ${gmime_cflags}
\r
109 > GMIME_LDFLAGS = ${gmime_ldflags}
\r
111 > +# Flags needed to compile and link against zlib
\r
112 > +ZLIB_CFLAGS = ${zlib_cflags}
\r
113 > +ZLIB_LDFLAGS = ${zlib_ldflags}
\r
115 > # Flags needed to compile and link against talloc
\r
116 > TALLOC_CFLAGS = ${talloc_cflags}
\r
117 > TALLOC_LDFLAGS = ${talloc_ldflags}
\r
118 > @@ -882,6 +898,7 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\r
119 > -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)
\r
121 > CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\r
122 > + \$(ZLIB_CFLAGS) \\
\r
123 > \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
\r
124 > \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS) \\
\r
125 > -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR) \\
\r
126 > @@ -892,5 +909,5 @@ CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\r
127 > -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT) \\
\r
128 > -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)
\r
130 > -CONFIGURE_LDFLAGS = \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)
\r
131 > +CONFIGURE_LDFLAGS = \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(ZLIB_LDFLAGS) \$(XAPIAN_LDFLAGS)
\r
133 > diff --git a/notmuch-client.h b/notmuch-client.h
\r
134 > index d110648..e1efbe0 100644
\r
135 > --- a/notmuch-client.h
\r
136 > +++ b/notmuch-client.h
\r
137 > @@ -450,7 +450,9 @@ typedef enum dump_formats {
\r
139 > notmuch_database_dump (notmuch_database_t *notmuch,
\r
140 > const char *output_file_name,
\r
141 > - const char *query_str, dump_format_t output_format);
\r
142 > + const char *query_str,
\r
143 > + dump_format_t output_format,
\r
144 > + notmuch_bool_t gzip_output);
\r
146 > #include "command-line-arguments.h"
\r
148 > diff --git a/notmuch-dump.c b/notmuch-dump.c
\r
149 > index 21702d7..029f90a 100644
\r
150 > --- a/notmuch-dump.c
\r
151 > +++ b/notmuch-dump.c
\r
152 > @@ -21,10 +21,12 @@
\r
153 > #include "notmuch-client.h"
\r
154 > #include "hex-escape.h"
\r
155 > #include "string-util.h"
\r
156 > +#include <zlib.h>
\r
160 > -database_dump_file (notmuch_database_t *notmuch, FILE *output,
\r
161 > - const char *query_str, int output_format)
\r
162 > +database_dump_file (notmuch_database_t *notmuch, gzFile output,
\r
163 > + const char *query_str, int output_format)
\r
165 > notmuch_query_t *query;
\r
166 > notmuch_messages_t *messages;
\r
167 > @@ -69,7 +71,7 @@ database_dump_file (notmuch_database_t *notmuch, FILE *output,
\r
170 > if (output_format == DUMP_FORMAT_SUP) {
\r
171 > - fprintf (output, "%s (", message_id);
\r
172 > + gzprintf (output, "%s (", message_id);
\r
175 > for (tags = notmuch_message_get_tags (message);
\r
176 > @@ -78,12 +80,12 @@ database_dump_file (notmuch_database_t *notmuch, FILE *output,
\r
177 > const char *tag_str = notmuch_tags_get (tags);
\r
180 > - fputs (" ", output);
\r
181 > + gzputs (output, " ");
\r
185 > if (output_format == DUMP_FORMAT_SUP) {
\r
186 > - fputs (tag_str, output);
\r
187 > + gzputs (output, tag_str);
\r
189 > if (hex_encode (notmuch, tag_str,
\r
190 > &buffer, &buffer_size) != HEX_SUCCESS) {
\r
191 > @@ -91,12 +93,12 @@ database_dump_file (notmuch_database_t *notmuch, FILE *output,
\r
193 > return EXIT_FAILURE;
\r
195 > - fprintf (output, "+%s", buffer);
\r
196 > + gzprintf (output, "+%s", buffer);
\r
200 > if (output_format == DUMP_FORMAT_SUP) {
\r
201 > - fputs (")\n", output);
\r
202 > + gzputs (output, ")\n");
\r
204 > if (make_boolean_term (notmuch, "id", message_id,
\r
205 > &buffer, &buffer_size)) {
\r
206 > @@ -104,7 +106,7 @@ database_dump_file (notmuch_database_t *notmuch, FILE *output,
\r
207 > message_id, strerror (errno));
\r
208 > return EXIT_FAILURE;
\r
210 > - fprintf (output, " -- %s\n", buffer);
\r
211 > + gzprintf (output, " -- %s\n", buffer);
\r
214 > notmuch_message_destroy (message);
\r
215 > @@ -121,24 +123,33 @@ database_dump_file (notmuch_database_t *notmuch, FILE *output,
\r
217 > notmuch_database_dump (notmuch_database_t *notmuch,
\r
218 > const char *output_file_name,
\r
219 > - const char *query_str, dump_format_t output_format)
\r
220 > + const char *query_str,
\r
221 > + dump_format_t output_format,
\r
222 > + notmuch_bool_t gzip_output)
\r
224 > - FILE *output = stdout;
\r
226 > + const char *mode = gzip_output ? "w9" : "wT";
\r
230 > if (output_file_name) {
\r
231 > - output = fopen (output_file_name, "w");
\r
232 > + output = gzopen (output_file_name, mode);
\r
233 > if (output == NULL) {
\r
234 > fprintf (stderr, "Error opening %s for writing: %s\n",
\r
235 > output_file_name, strerror (errno));
\r
236 > return EXIT_FAILURE;
\r
239 > + output = gzdopen (fileno (stdout), mode);
\r
242 > ret = database_dump_file (notmuch, output, query_str, output_format);
\r
244 > - if (output != stdout)
\r
245 > - fclose (output);
\r
246 > + /* XXX check error return */
\r
247 > + gzflush (output, Z_FINISH);
\r
249 > + if (output_file_name)
\r
250 > + gzclose_w (output);
\r
254 > @@ -158,6 +169,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
257 > int output_format = DUMP_FORMAT_BATCH_TAG;
\r
258 > + notmuch_bool_t gzip_output = 0;
\r
260 > notmuch_opt_desc_t options[] = {
\r
261 > { NOTMUCH_OPT_KEYWORD, &output_format, "format", 'f',
\r
262 > @@ -165,6 +177,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
263 > { "batch-tag", DUMP_FORMAT_BATCH_TAG },
\r
265 > { NOTMUCH_OPT_STRING, &output_file_name, "output", 'o', 0 },
\r
266 > + { NOTMUCH_OPT_BOOLEAN, &gzip_output, "gzip", 'z', 0 },
\r
267 > { 0, 0, 0, 0, 0 }
\r
270 > @@ -181,7 +194,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
273 > ret = notmuch_database_dump (notmuch, output_file_name, query_str,
\r
274 > - output_format);
\r
275 > + output_format, gzip_output);
\r
277 > notmuch_database_destroy (notmuch);
\r
282 > _______________________________________________
\r
283 > notmuch mailing list
\r
284 > notmuch@notmuchmail.org
\r
285 > http://notmuchmail.org/mailman/listinfo/notmuch
\r