[PATCH 1/3] Add notmuch_database_close_compact
authorBen Gamari <bgamari.foss@gmail.com>
Mon, 20 Aug 2012 15:31:42 +0000 (11:31 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:49:10 +0000 (09:49 -0800)
82/b09041f20a16883bbe858a75ff430f1f1c349a [new file with mode: 0644]

diff --git a/82/b09041f20a16883bbe858a75ff430f1f1c349a b/82/b09041f20a16883bbe858a75ff430f1f1c349a
new file mode 100644 (file)
index 0000000..8814d11
--- /dev/null
@@ -0,0 +1,217 @@
+Return-Path: <bgamari.foss@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 5A5AE431FBD\r
+       for <notmuch@notmuchmail.org>; Mon, 20 Aug 2012 08:31:55 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id ErJhg5vvKABW for <notmuch@notmuchmail.org>;\r
+       Mon, 20 Aug 2012 08:31:54 -0700 (PDT)\r
+Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com\r
+       [209.85.220.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 10C7D431FB6\r
+       for <notmuch@notmuchmail.org>; Mon, 20 Aug 2012 08:31:54 -0700 (PDT)\r
+Received: by vcbfl17 with SMTP id fl17so5583578vcb.26\r
+       for <notmuch@notmuchmail.org>; Mon, 20 Aug 2012 08:31:53 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+       bh=X8latOgPe5F1HW8xbEc0KD5kZQWSq7L2zUrP5eu0Zgo=;\r
+       b=QpaJiWOn7ebas/YPZIsc1EVMB9U4lVpvLkqSLu0n8ajWWbSiusooy8hPesbKmbmTct\r
+       atTuvcQxfFwALsXAokcJbNqksrgcv8ygoHRC2IvqSMQA8AyttP7LX2WLZbj+yMVVmCBV\r
+       sNKQ4CXAvUCCbIbyBl0qLunFZ57CztLprfiZnSPHQ55M7iUoUir2QJ7TB0i/5rC++k7k\r
+       YzBGdcQYxEjJ8Y0DGFA0rhZdfHLANpfABPHoPg8wyD8Yq0Pc7JyLrIkOtokFGF8uXOy4\r
+       OY72CjQUYwJQxgJhZG+XKXEFNhmryhqKuMftCEq4rLNpUQM4Hwd6tv4yFkec6CrqW76q\r
+       Y0hQ==\r
+Received: by 10.58.4.232 with SMTP id n8mr11357600ven.54.1345476713428;\r
+       Mon, 20 Aug 2012 08:31:53 -0700 (PDT)\r
+Received: from localhost.localdomain\r
+       (pool-108-8-230-85.spfdma.east.verizon.net. [108.8.230.85])\r
+       by mx.google.com with ESMTPS id g10sm5430786vdk.2.2012.08.20.08.31.52\r
+       (version=SSLv3 cipher=OTHER); Mon, 20 Aug 2012 08:31:52 -0700 (PDT)\r
+From: Ben Gamari <bgamari.foss@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/3] Add notmuch_database_close_compact\r
+Date: Mon, 20 Aug 2012 11:31:42 -0400\r
+Message-Id: <1345476704-17091-2-git-send-email-bgamari.foss@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.5\r
+In-Reply-To: <1345476704-17091-1-git-send-email-bgamari.foss@gmail.com>\r
+References: <1345476704-17091-1-git-send-email-bgamari.foss@gmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 20 Aug 2012 15:31:55 -0000\r
+\r
+---\r
+ configure       |   25 ++++++++++++++++++++++++-\r
+ lib/database.cc |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ lib/notmuch.h   |   14 ++++++++++++++\r
+ 3 files changed, 92 insertions(+), 1 deletion(-)\r
+\r
+diff --git a/configure b/configure\r
+index dc0dba4..370fedd 100755\r
+--- a/configure\r
++++ b/configure\r
+@@ -270,7 +270,8 @@ printf "Checking for Xapian development files... "\r
+ have_xapian=0\r
+ for xapian_config in ${XAPIAN_CONFIG}; do\r
+     if ${xapian_config} --version > /dev/null 2>&1; then\r
+-      printf "Yes (%s).\n" $(${xapian_config} --version | sed -e 's/.* //')\r
++      xapian_version=$(${xapian_config} --version | sed -e 's/.* //')\r
++      printf "Yes (%s).\n" ${xapian_version}\r
+       have_xapian=1\r
+       xapian_cxxflags=$(${xapian_config} --cxxflags)\r
+       xapian_ldflags=$(${xapian_config} --libs)\r
+@@ -282,6 +283,24 @@ if [ ${have_xapian} = "0" ]; then\r
+     errors=$((errors + 1))\r
+ fi\r
\r
++have_xapian_compact=0\r
++if [ ${have_xapian} = "1" ]; then\r
++    printf "Checking for Xapian compact support... "\r
++    IFS='.'\r
++    old_args=$@\r
++    set -- ${xapian_version}\r
++    xapian_major_version=$1\r
++    xapian_minor_version=$2\r
++    xapian_subminor_version=$3\r
++    set -- ${old_args}\r
++    if [ "${xapian_major_version}" -gt 1 ] || [ ${xapian_minor_version} -gt 2 ] || [ ${xapian_subminor_version} -ge 6 ]; then\r
++      printf "Yes.\n"\r
++      have_xapian_compact=1\r
++    else\r
++      printf "No.\n"\r
++    fi\r
++fi\r
++\r
+ printf "Checking for GMime development files... "\r
+ have_gmime=0\r
+ IFS=';'\r
+@@ -675,6 +694,9 @@ LINKER_RESOLVES_LIBRARY_DEPENDENCIES = ${linker_resolves_library_dependencies}\r
+ XAPIAN_CXXFLAGS = ${xapian_cxxflags}\r
+ XAPIAN_LDFLAGS = ${xapian_ldflags}\r
\r
++# Whether compact is supported by this version of Xapian\r
++HAVE_XAPIAN_COMPACT = ${have_xapian_compact}\r
++\r
+ # Flags needed to compile and link against GMime-2.4\r
+ GMIME_CFLAGS = ${gmime_cflags}\r
+ GMIME_LDFLAGS = ${gmime_ldflags}\r
+@@ -711,6 +733,7 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\\r
+ CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\\r
+                    \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\\r
+                    \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS)             \\\r
++                     -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)       \\\r
+                      -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)\r
+ CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)\r
+ EOF\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 761dc1a..6e83a61 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -781,6 +781,60 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
+ }\r
\r
+ void\r
++notmuch_database_close_compact (notmuch_database_t *notmuch)\r
++{\r
++    void *local = talloc_new (NULL);\r
++    Xapian::Compactor compactor;\r
++    char *notmuch_path, *xapian_path, *compact_xapian_path, *old_xapian_path;\r
++\r
++#if HAVE_XAPIAN_COMPACT\r
++    if (! (notmuch_path = talloc_asprintf (local, "%s/%s", notmuch->path, ".notmuch"))) {\r
++      fprintf (stderr, "Out of memory\n");\r
++      goto DONE;\r
++    }\r
++\r
++    if (! (xapian_path = talloc_asprintf (local, "%s/%s", notmuch_path, "xapian"))) {\r
++      fprintf (stderr, "Out of memory\n");\r
++      goto DONE;\r
++    }\r
++\r
++    if (! (compact_xapian_path = talloc_asprintf (local, "%s.compact", xapian_path))) {\r
++      fprintf (stderr, "Out of memory\n");\r
++      goto DONE;\r
++    }\r
++\r
++    if (! (old_xapian_path = talloc_asprintf (local, "%s.old", xapian_path))) {\r
++      fprintf (stderr, "Out of memory\n");\r
++      goto DONE;\r
++    }\r
++\r
++    try {\r
++      compactor.set_renumber(false);\r
++      compactor.add_source(xapian_path);\r
++      compactor.set_destdir(compact_xapian_path);\r
++      compactor.compact();\r
++\r
++      if (rename(xapian_path, old_xapian_path)) {\r
++          fprintf (stderr, "Error moving old database out of the way\n");\r
++          goto DONE;\r
++      }\r
++\r
++      if (rename(compact_xapian_path, xapian_path)) {\r
++          fprintf (stderr, "Error moving compacted database\n");\r
++          goto DONE;\r
++      }\r
++    } catch (Xapian::InvalidArgumentError e) {\r
++      fprintf (stderr, "Error while compacting: %s", e.get_msg().c_str());\r
++    }\r
++    \r
++#endif\r
++\r
++    notmuch_database_close(notmuch);\r
++DONE:\r
++    talloc_free(local);\r
++}\r
++\r
++void\r
+ notmuch_database_destroy (notmuch_database_t *notmuch)\r
+ {\r
+     notmuch_database_close (notmuch);\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 3633bed..50babfb 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -215,6 +215,20 @@ notmuch_database_open (const char *path,\r
+ void\r
+ notmuch_database_close (notmuch_database_t *database);\r
\r
++/* Close the given notmuch database and then compact it.\r
++ *\r
++ * After notmuch_database_close_compact has been called, calls to\r
++ * other functions on objects derived from this database may either\r
++ * behave as if the database had not been closed (e.g., if the\r
++ * required data has been cached) or may fail with a\r
++ * NOTMUCH_STATUS_XAPIAN_EXCEPTION.\r
++ *\r
++ * notmuch_database_close_compact can be called multiple times.  Later\r
++ * calls have no effect.\r
++ */\r
++void\r
++notmuch_database_close_compact (notmuch_database_t *notmuch);\r
++\r
+ /* Destroy the notmuch database, closing it if necessary and freeing\r
+ * all associated resources. */\r
+ void\r
+-- \r
+1.7.9.5\r
+\r