1 Return-Path: <bgamari.foss@gmail.com>
\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 393F6431FC4
\r
6 for <notmuch@notmuchmail.org>; Wed, 17 Oct 2012 08:29:41 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id QqpPI8iMmGQz for <notmuch@notmuchmail.org>;
\r
17 Wed, 17 Oct 2012 08:29:39 -0700 (PDT)
\r
18 Received: from mail-qa0-f53.google.com (mail-qa0-f53.google.com
\r
19 [209.85.216.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id C923D431FBD
\r
22 for <notmuch@notmuchmail.org>; Wed, 17 Oct 2012 08:29:39 -0700 (PDT)
\r
23 Received: by mail-qa0-f53.google.com with SMTP id s11so640771qaa.5
\r
24 for <notmuch@notmuchmail.org>; Wed, 17 Oct 2012 08:29:38 -0700 (PDT)
\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
\r
26 h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;
\r
27 bh=R7lPcHbeLwXLL8I3ZI019OfJgN241NwP0vgjv/5EGSg=;
\r
28 b=Lrx6lyPGQPtk+CFruF8nf0Ii4NpvtQ88swtUofW1Elmeh/Oi6v4mBnl+hVTsrTH9HT
\r
29 DcLKjxyw8ZRTuujOatXajX1Sip+YbhLsc4GJ+tcBLDVs57QzgtZUQMip7V0nw9L8c6x/
\r
30 acele8eKpUMc363OpE7EUlJHmNYZvqIdfUZFQtRPFxDYi9OhUHc2kwHHmyRZEF2UC59d
\r
31 pq63AQgX0o670asEhq5XE+tMWGS8kfBuGf3ZthTWhosOMrVfU618XEnNBKOgxVZNubh/
\r
32 kYUV6LuSyvOfL72dsswlw1bI3HGu8MUHAV5igfXHPKhi285vT3Fs28yTUfxe3KmT6d2Q
\r
34 Received: by 10.229.69.67 with SMTP id y3mr8701964qci.136.1350487778104;
\r
35 Wed, 17 Oct 2012 08:29:38 -0700 (PDT)
\r
36 Received: from ben-laptop.hasb.physics.cns (physicsnat56.physics.umass.edu.
\r
38 by mx.google.com with ESMTPS id eq10sm13366039qab.0.2012.10.17.08.29.37
\r
39 (version=SSLv3 cipher=OTHER); Wed, 17 Oct 2012 08:29:37 -0700 (PDT)
\r
40 From: Ben Gamari <bgamari.foss@gmail.com>
\r
41 To: notmuch@notmuchmail.org
\r
42 Subject: [PATCH 1/3] Add notmuch_database_close_compact
\r
43 Date: Wed, 17 Oct 2012 11:28:55 -0400
\r
44 Message-Id: <1350487737-32058-2-git-send-email-bgamari.foss@gmail.com>
\r
45 X-Mailer: git-send-email 1.7.10.4
\r
46 In-Reply-To: <1350487737-32058-1-git-send-email-bgamari.foss@gmail.com>
\r
47 References: <1350487737-32058-1-git-send-email-bgamari.foss@gmail.com>
\r
48 X-BeenThere: notmuch@notmuchmail.org
\r
49 X-Mailman-Version: 2.1.13
\r
51 List-Id: "Use and development of the notmuch mail system."
\r
52 <notmuch.notmuchmail.org>
\r
53 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
54 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
55 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
56 List-Post: <mailto:notmuch@notmuchmail.org>
\r
57 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
58 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
59 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
60 X-List-Received-Date: Wed, 17 Oct 2012 15:29:41 -0000
\r
63 configure | 21 ++++++++++++++++++++-
\r
64 lib/database.cc | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
65 lib/notmuch.h | 14 ++++++++++++++
\r
66 3 files changed, 88 insertions(+), 1 deletion(-)
\r
68 diff --git a/configure b/configure
\r
69 index acb90a8..6551b13 100755
\r
72 @@ -270,7 +270,8 @@ printf "Checking for Xapian development files... "
\r
74 for xapian_config in ${XAPIAN_CONFIG}; do
\r
75 if ${xapian_config} --version > /dev/null 2>&1; then
\r
76 - printf "Yes (%s).\n" $(${xapian_config} --version | sed -e 's/.* //')
\r
77 + xapian_version=$(${xapian_config} --version | sed -e 's/.* //')
\r
78 + printf "Yes (%s).\n" ${xapian_version}
\r
80 xapian_cxxflags=$(${xapian_config} --cxxflags)
\r
81 xapian_ldflags=$(${xapian_config} --libs)
\r
82 @@ -282,6 +283,20 @@ if [ ${have_xapian} = "0" ]; then
\r
83 errors=$((errors + 1))
\r
86 +have_xapian_compact=0
\r
87 +if [ ${have_xapian} = "1" ]; then
\r
88 + printf "Checking for Xapian compact support... "
\r
89 + case "${xapian_version}" in
\r
90 + 0.*|1.[01].*|1.2.[0-5])
\r
92 + [1-9]*.[0-9]*.[0-9]*)
\r
93 + have_xapian_compact=1
\r
94 + printf "Yes.\n" ;;
\r
96 + printf "Unknown version.\n" ;;
\r
100 printf "Checking for GMime development files... "
\r
103 @@ -679,6 +694,9 @@ LINKER_RESOLVES_LIBRARY_DEPENDENCIES = ${linker_resolves_library_dependencies}
\r
104 XAPIAN_CXXFLAGS = ${xapian_cxxflags}
\r
105 XAPIAN_LDFLAGS = ${xapian_ldflags}
\r
107 +# Whether compact is supported by this version of Xapian
\r
108 +HAVE_XAPIAN_COMPACT = ${have_xapian_compact}
\r
110 # Flags needed to compile and link against GMime-2.4
\r
111 GMIME_CFLAGS = ${gmime_cflags}
\r
112 GMIME_LDFLAGS = ${gmime_ldflags}
\r
113 @@ -715,6 +733,7 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\r
114 CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\
\r
115 \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\
\r
116 \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS) \\
\r
117 + -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT) \\
\r
118 -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)
\r
119 CONFIGURE_LDFLAGS = \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)
\r
121 diff --git a/lib/database.cc b/lib/database.cc
\r
122 index 761dc1a..6e83a61 100644
\r
123 --- a/lib/database.cc
\r
124 +++ b/lib/database.cc
\r
125 @@ -781,6 +781,60 @@ notmuch_database_close (notmuch_database_t *notmuch)
\r
129 +notmuch_database_close_compact (notmuch_database_t *notmuch)
\r
131 + void *local = talloc_new (NULL);
\r
132 + Xapian::Compactor compactor;
\r
133 + char *notmuch_path, *xapian_path, *compact_xapian_path, *old_xapian_path;
\r
135 +#if HAVE_XAPIAN_COMPACT
\r
136 + if (! (notmuch_path = talloc_asprintf (local, "%s/%s", notmuch->path, ".notmuch"))) {
\r
137 + fprintf (stderr, "Out of memory\n");
\r
141 + if (! (xapian_path = talloc_asprintf (local, "%s/%s", notmuch_path, "xapian"))) {
\r
142 + fprintf (stderr, "Out of memory\n");
\r
146 + if (! (compact_xapian_path = talloc_asprintf (local, "%s.compact", xapian_path))) {
\r
147 + fprintf (stderr, "Out of memory\n");
\r
151 + if (! (old_xapian_path = talloc_asprintf (local, "%s.old", xapian_path))) {
\r
152 + fprintf (stderr, "Out of memory\n");
\r
157 + compactor.set_renumber(false);
\r
158 + compactor.add_source(xapian_path);
\r
159 + compactor.set_destdir(compact_xapian_path);
\r
160 + compactor.compact();
\r
162 + if (rename(xapian_path, old_xapian_path)) {
\r
163 + fprintf (stderr, "Error moving old database out of the way\n");
\r
167 + if (rename(compact_xapian_path, xapian_path)) {
\r
168 + fprintf (stderr, "Error moving compacted database\n");
\r
171 + } catch (Xapian::InvalidArgumentError e) {
\r
172 + fprintf (stderr, "Error while compacting: %s", e.get_msg().c_str());
\r
177 + notmuch_database_close(notmuch);
\r
179 + talloc_free(local);
\r
183 notmuch_database_destroy (notmuch_database_t *notmuch)
\r
185 notmuch_database_close (notmuch);
\r
186 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
187 index 3633bed..50babfb 100644
\r
188 --- a/lib/notmuch.h
\r
189 +++ b/lib/notmuch.h
\r
190 @@ -215,6 +215,20 @@ notmuch_database_open (const char *path,
\r
192 notmuch_database_close (notmuch_database_t *database);
\r
194 +/* Close the given notmuch database and then compact it.
\r
196 + * After notmuch_database_close_compact has been called, calls to
\r
197 + * other functions on objects derived from this database may either
\r
198 + * behave as if the database had not been closed (e.g., if the
\r
199 + * required data has been cached) or may fail with a
\r
200 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION.
\r
202 + * notmuch_database_close_compact can be called multiple times. Later
\r
203 + * calls have no effect.
\r
206 +notmuch_database_close_compact (notmuch_database_t *notmuch);
\r
208 /* Destroy the notmuch database, closing it if necessary and freeing
\r
209 * all associated resources. */
\r