--- /dev/null
+Return-Path: <amdragon@mit.edu>\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 D8D26431FAE\r
+ for <notmuch@notmuchmail.org>; Thu, 31 Jul 2014 19:10:29 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_MED=-2.3] 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 FRi3YozE78Vc for <notmuch@notmuchmail.org>;\r
+ Thu, 31 Jul 2014 19:10:23 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-6.mit.edu (dmz-mailsec-scanner-6.mit.edu\r
+ [18.7.68.35])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id AC54A431FC0\r
+ for <notmuch@notmuchmail.org>; Thu, 31 Jul 2014 19:10:12 -0700 (PDT)\r
+X-AuditID: 12074423-f79bf6d000007580-d8-53daf7042ee8\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+ (using TLS with cipher AES256-SHA (256/256 bits))\r
+ (Client did not present a certificate)\r
+ by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id D1.55.30080.407FAD35; Thu, 31 Jul 2014 22:10:12 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+ by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id s712A98o007827; \r
+ Thu, 31 Jul 2014 22:10:10 -0400\r
+Received: from drake.dyndns.org\r
+ (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+ [216.15.114.40]) (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s712A74O029993\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Thu, 31 Jul 2014 22:10:09 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1XD2II-00033y-8R; Thu, 31 Jul 2014 22:10:06 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 12/13] lib: Return an error from operations that require an\r
+ upgrade\r
+Date: Thu, 31 Jul 2014 22:10:02 -0400\r
+Message-Id: <1406859003-11561-13-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 2.0.0\r
+In-Reply-To: <1406859003-11561-1-git-send-email-amdragon@mit.edu>\r
+References: <1406859003-11561-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrFIsWRmVeSWpSXmKPExsUixG6nosvy/VawwYyJMhar5/JYXL85k9mB\r
+ yWPnrLvsHs9W3WIOYIrisklJzcksSy3St0vgyjj7eBtrwQ3tisYna5gbGJtVuhg5OSQETCQu\r
+ zjnPCmGLSVy4t54NxBYSmM0k8eqUWxcjF5C9kVGiYedWNgjnDpPE3R1HWSGcuYwSizd/BGth\r
+ E9CQ2LZ/OSOILSIgLbHz7mywscwCjhKf9y8CqxEWCJPo+vWZvYuRg4NFQFXi/lpbEJMXqOTV\r
+ KgeII+QkGm58AqvmBAr//7eAFeIgB4nW01uZJzDyL2BkWMUom5JbpZubmJlTnJqsW5ycmJeX\r
+ WqRrppebWaKXmlK6iREcRC7KOxj/HFQ6xCjAwajEwzsj/FawEGtiWXFl7iFGSQ4mJVFem49A\r
+ Ib6k/JTKjMTijPii0pzU4kOMEhzMSiK8Lz8A5XhTEiurUovyYVLSHCxK4rxvra2ChQTSE0tS\r
+ s1NTC1KLYLIyHBxKErxnvgI1ChalpqdWpGXmlCCkmTg4QYbzAA2/BlLDW1yQmFucmQ6RP8Wo\r
+ KCXOuwckIQCSyCjNg+uFRfkrRnGgV4R5H4JU8QATBFz3K6DBTECDn9+6DjK4JBEhJdXAaOiW\r
+ d33xoZiC4A+PT6hb/TjwzmR3V/nMA7+eRxlvj4jde5uPt4R3slGeqamPUdHU10cfrvj07vuZ\r
+ +fV30sJlWeWea6yW++rw2+zc5wONoStMDm5aackq+Px50rKYVbULzLUXvZ6xPdvbr0Hez0kk\r
+ Y8Kcltldi9XTkktOsRcz2lwo49w+YVO6sBJLcUaioRZzUXEiAG+P/3bNAgAA\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: Fri, 01 Aug 2014 02:10:30 -0000\r
+\r
+Previously, there was no protection against a caller invoking an\r
+operation on an old database version that would effectively corrupt\r
+the database by treating it like a newer version.\r
+\r
+According to notmuch.h, any caller that opens the database in\r
+read/write mode is supposed to check if the database needs upgrading\r
+and perform an upgrade if it does. This would protect against this,\r
+but nobody (even the CLI) actually does this.\r
+\r
+However, with features, it's easy to protect against incompatible\r
+operations on a fine-grained basis. This lightweight change allows\r
+callers to safely operate on old database versions, while preventing\r
+specific operations that would corrupt the database with an\r
+informative error message.\r
+---\r
+ lib/database.cc | 5 +++++\r
+ lib/directory.cc | 5 +++++\r
+ lib/message.cc | 8 ++++++++\r
+ lib/notmuch.h | 16 ++++++++++++++++\r
+ 4 files changed, 34 insertions(+)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 04b3790..d90a924 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -310,6 +310,8 @@ notmuch_status_to_string (notmuch_status_t status)\r
+ return "Unbalanced number of calls to notmuch_database_begin_atomic/end_atomic";\r
+ case NOTMUCH_STATUS_UNSUPPORTED_OPERATION:\r
+ return "Unsupported operation";\r
++ case NOTMUCH_STATUS_UPGRADE_REQUIRED:\r
++ return "Operation requires a database upgrade";\r
+ default:\r
+ case NOTMUCH_STATUS_LAST_STATUS:\r
+ return "Unknown error status value";\r
+@@ -2219,6 +2221,9 @@ notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,\r
+ if (message_ret == NULL)\r
+ return NOTMUCH_STATUS_NULL_POINTER;\r
+ \r
++ if (! (notmuch->features & NOTMUCH_FEATURE_FILE_TERMS))\r
++ return NOTMUCH_STATUS_UPGRADE_REQUIRED;\r
++\r
+ /* return NULL on any failure */\r
+ *message_ret = NULL;\r
+ \r
+diff --git a/lib/directory.cc b/lib/directory.cc\r
+index 6a3ffed..8daaec8 100644\r
+--- a/lib/directory.cc\r
++++ b/lib/directory.cc\r
+@@ -105,6 +105,11 @@ _notmuch_directory_create (notmuch_database_t *notmuch,\r
+ const char *db_path;\r
+ notmuch_bool_t create = (flags & NOTMUCH_FIND_CREATE);\r
+ \r
++ if (! (notmuch->features & NOTMUCH_FEATURE_DIRECTORY_DOCS)) {\r
++ *status_ret = NOTMUCH_STATUS_UPGRADE_REQUIRED;\r
++ return NULL;\r
++ }\r
++\r
+ *status_ret = NOTMUCH_STATUS_SUCCESS;\r
+ \r
+ path = _notmuch_database_relative_path (notmuch, path);\r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index 4fc427f..1618e81 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -653,6 +653,10 @@ _notmuch_message_add_filename (notmuch_message_t *message,\r
+ if (filename == NULL)\r
+ INTERNAL_ERROR ("Message filename cannot be NULL.");\r
+ \r
++ if (! (message->notmuch->features & NOTMUCH_FEATURE_FILE_TERMS) ||\r
++ ! (message->notmuch->features & NOTMUCH_FEATURE_BOOL_FOLDER))\r
++ return NOTMUCH_STATUS_UPGRADE_REQUIRED;\r
++\r
+ relative = _notmuch_database_relative_path (message->notmuch, filename);\r
+ \r
+ status = _notmuch_database_split_path (local, relative, &directory, NULL);\r
+@@ -697,6 +701,10 @@ _notmuch_message_remove_filename (notmuch_message_t *message,\r
+ notmuch_private_status_t private_status;\r
+ notmuch_status_t status;\r
+ \r
++ if (! (message->notmuch->features & NOTMUCH_FEATURE_FILE_TERMS) ||\r
++ ! (message->notmuch->features & NOTMUCH_FEATURE_BOOL_FOLDER))\r
++ return NOTMUCH_STATUS_UPGRADE_REQUIRED;\r
++\r
+ status = _notmuch_database_filename_to_direntry (\r
+ local, message->notmuch, filename, NOTMUCH_FIND_LOOKUP, &direntry);\r
+ if (status || !direntry)\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 3c5ec98..cbf2ba5 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -160,6 +160,10 @@ typedef enum _notmuch_status {\r
+ */\r
+ NOTMUCH_STATUS_UNSUPPORTED_OPERATION,\r
+ /**\r
++ * The operation requires a database upgrade.\r
++ */\r
++ NOTMUCH_STATUS_UPGRADE_REQUIRED,\r
++ /**\r
+ * Not an actual status value. Just a way to find out how many\r
+ * valid status values there are.\r
+ */\r
+@@ -438,6 +442,9 @@ notmuch_database_end_atomic (notmuch_database_t *notmuch);\r
+ *\r
+ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred;\r
+ * directory not retrieved.\r
++ *\r
++ * NOTMUCH_STATUS_UPGRADE_REQUIRED: The caller must upgrade the\r
++ * database to use this function.\r
+ */\r
+ notmuch_status_t\r
+ notmuch_database_get_directory (notmuch_database_t *database,\r
+@@ -490,6 +497,9 @@ notmuch_database_get_directory (notmuch_database_t *database,\r
+ *\r
+ * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only\r
+ * mode so no message can be added.\r
++ *\r
++ * NOTMUCH_STATUS_UPGRADE_REQUIRED: The caller must upgrade the\r
++ * database to use this function.\r
+ */\r
+ notmuch_status_t\r
+ notmuch_database_add_message (notmuch_database_t *database,\r
+@@ -520,6 +530,9 @@ notmuch_database_add_message (notmuch_database_t *database,\r
+ *\r
+ * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only\r
+ * mode so no message can be removed.\r
++ *\r
++ * NOTMUCH_STATUS_UPGRADE_REQUIRED: The caller must upgrade the\r
++ * database to use this function.\r
+ */\r
+ notmuch_status_t\r
+ notmuch_database_remove_message (notmuch_database_t *database,\r
+@@ -575,6 +588,9 @@ notmuch_database_find_message (notmuch_database_t *database,\r
+ * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory, creating the message object\r
+ *\r
+ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred\r
++ *\r
++ * NOTMUCH_STATUS_UPGRADE_REQUIRED: The caller must upgrade the\r
++ * database to use this function.\r
+ */\r
+ notmuch_status_t\r
+ notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,\r
+-- \r
+2.0.0\r
+\r