[PATCH v2] lib: add return status to database close and destroy
authorJani Nikula <jani@nikula.org>
Sun, 19 Jan 2014 17:20:46 +0000 (19:20 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:59:09 +0000 (09:59 -0800)
38/27af77704565f33229ca41a6c179f7262be8de [new file with mode: 0644]

diff --git a/38/27af77704565f33229ca41a6c179f7262be8de b/38/27af77704565f33229ca41a6c179f7262be8de
new file mode 100644 (file)
index 0000000..d2fbcdf
--- /dev/null
@@ -0,0 +1,196 @@
+Return-Path: <jani@nikula.org>\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 3DCA5431FC0\r
+       for <notmuch@notmuchmail.org>; Sun, 19 Jan 2014 09:21:02 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[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 RW3jJQhRq-c9 for <notmuch@notmuchmail.org>;\r
+       Sun, 19 Jan 2014 09:20:53 -0800 (PST)\r
+Received: from mail-ea0-f180.google.com (mail-ea0-f180.google.com\r
+       [209.85.215.180]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 24FE8431FBD\r
+       for <notmuch@notmuchmail.org>; Sun, 19 Jan 2014 09:20:53 -0800 (PST)\r
+Received: by mail-ea0-f180.google.com with SMTP id f15so2654834eak.39\r
+       for <notmuch@notmuchmail.org>; Sun, 19 Jan 2014 09:20:50 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=1e100.net; s=20130820;\r
+       h=x-gm-message-state:from:to:cc:subject:date:message-id;\r
+       bh=FM78c4W+E5Vv6uxqS07KLcar+lVzJdx9zl+rOiS8Okw=;\r
+       b=KZh6682lEtKeNiWJydd6PD4tGLSrEDvH3Stmp5zYzvi3uMFXtuqUYCHZSlEvt0JcgM\r
+       i5k9NeWp9YZLak4OBsCAt9OB5XOX0Bod3oi25cZYhHkBciIphQHGpKWfmU6w/hfKXwgv\r
+       ZRGLsTwtvSArla4G4S+kRkzGGuYCopf6AoY6AIM2xBy/31BqyD//qM+e3bPl/vhD3/Jt\r
+       Ckf6T+iQzmH9eIZsP2i6TQwZcMrUIpzJQRFs1421ooDbIB6PKR3FA0QBDbyR+6nVkc5/\r
+       Giu7Yhmf6pu/5BAuD14fSOenSOTuNc2Hl3xqRuwroBEy3fUtovf/u2pr6Zbb5YbrBaAB\r
+       z8pQ==\r
+X-Gm-Message-State:\r
+ ALoCoQl0dfncpSZUdqwSLNHe6FqKkGS9lTPIYK+B6uOAnUAC+SNhRVsbs1NNQ5v4EvFNip7ZRYYc\r
+X-Received: by 10.14.114.70 with SMTP id b46mr203478eeh.84.1390152049132;\r
+       Sun, 19 Jan 2014 09:20:49 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.\r
+       [88.195.111.91]) by mx.google.com with ESMTPSA id\r
+       o47sm45284052eem.21.2014.01.19.09.20.47 for <multiple recipients>\r
+       (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+       Sun, 19 Jan 2014 09:20:48 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2] lib: add return status to database close and destroy\r
+Date: Sun, 19 Jan 2014 19:20:46 +0200\r
+Message-Id: <1390152046-6509-1-git-send-email-jani@nikula.org>\r
+X-Mailer: git-send-email 1.8.5.2\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: Sun, 19 Jan 2014 17:21:02 -0000\r
+\r
+notmuch_database_close may fail in Xapian ->flush() or ->close(), so\r
+report the status. Similarly for notmuch_database_destroy which calls\r
+close.\r
+\r
+This is required for notmuch insert to report error status if message\r
+indexing failed.\r
+\r
+---\r
+\r
+v2 of\r
+id:29b808bb6bf051fe21b6a72f12bb4ad1badfbf97.1385903109.git.jani@nikula.org\r
+picked out of the series.\r
+---\r
+ lib/database.cc | 30 ++++++++++++++++++++++++------\r
+ lib/notmuch.h   | 15 +++++++++++++--\r
+ 2 files changed, 37 insertions(+), 8 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index f395061..46a9a8f 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -767,14 +767,17 @@ notmuch_database_open (const char *path,\r
+     return status;\r
+ }\r
\r
+-void\r
++notmuch_status_t\r
+ notmuch_database_close (notmuch_database_t *notmuch)\r
+ {\r
++    notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
++\r
+     try {\r
+       if (notmuch->xapian_db != NULL &&\r
+           notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE)\r
+           (static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->flush ();\r
+     } catch (const Xapian::Error &error) {\r
++      status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+       if (! notmuch->exception_reported) {\r
+           fprintf (stderr, "Error: A Xapian exception occurred flushing database: %s\n",\r
+                    error.get_msg().c_str());\r
+@@ -788,7 +791,9 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
+       try {\r
+           notmuch->xapian_db->close();\r
+       } catch (const Xapian::Error &error) {\r
+-          /* do nothing */\r
++          /* don't clobber previous error status */\r
++          if (status == NOTMUCH_STATUS_SUCCESS)\r
++              status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+       }\r
+     }\r
\r
+@@ -802,6 +807,8 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
+     notmuch->value_range_processor = NULL;\r
+     delete notmuch->date_range_processor;\r
+     notmuch->date_range_processor = NULL;\r
++\r
++    return status;\r
+ }\r
\r
+ #if HAVE_XAPIAN_COMPACT\r
+@@ -965,8 +972,15 @@ notmuch_database_compact (const char *path,\r
+     }\r
\r
+   DONE:\r
+-    if (notmuch)\r
+-      notmuch_database_destroy (notmuch);\r
++    if (notmuch) {\r
++      notmuch_status_t ret2;\r
++\r
++      ret2 = notmuch_database_destroy (notmuch);\r
++\r
++      /* don't clobber previous error status */\r
++      if (ret == NOTMUCH_STATUS_SUCCESS && ret2 != NOTMUCH_STATUS_SUCCESS)\r
++          ret = ret2;\r
++    }\r
\r
+     talloc_free (local);\r
\r
+@@ -984,11 +998,15 @@ notmuch_database_compact (unused (const char *path),\r
+ }\r
+ #endif\r
\r
+-void\r
++notmuch_status_t\r
+ notmuch_database_destroy (notmuch_database_t *notmuch)\r
+ {\r
+-    notmuch_database_close (notmuch);\r
++    notmuch_status_t status;\r
++\r
++    status = notmuch_database_close (notmuch);\r
+     talloc_free (notmuch);\r
++\r
++    return status;\r
+ }\r
\r
+ const char *\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 02604c5..7ac7118 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -287,8 +287,16 @@ notmuch_database_open (const char *path,\r
+  *\r
+  * notmuch_database_close can be called multiple times.  Later calls\r
+  * have no effect.\r
++ *\r
++ * Return value:\r
++ *\r
++ * NOTMUCH_STATUS_SUCCESS: Successfully closed the database.\r
++ *\r
++ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred; the\r
++ *    database has been closed but there are no guarantees the\r
++ *    changes to the database, if any, have been flushed to disk.\r
+  */\r
+-void\r
++notmuch_status_t\r
+ notmuch_database_close (notmuch_database_t *database);\r
\r
+ /**\r
+@@ -317,8 +325,11 @@ notmuch_database_compact (const char* path,\r
+ /**\r
+  * Destroy the notmuch database, closing it if necessary and freeing\r
+  * all associated resources.\r
++ *\r
++ * Return value as in notmuch_database_close if the database was open;\r
++ * notmuch_database_destroy itself has no failure modes.\r
+  */\r
+-void\r
++notmuch_status_t\r
+ notmuch_database_destroy (notmuch_database_t *database);\r
\r
+ /**\r
+-- \r
+1.8.5.2\r
+\r