[PATCH v1 0/2] emacs: Improve notmuch-wash customisation.
[notmuch-archives.git] / e8 / 542ee627d43532d6a7667ffaf105da52995cc9
1 Return-Path: <amdragon@mit.edu>\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 D8D26431FAE\r
6         for <notmuch@notmuchmail.org>; Thu, 31 Jul 2014 19:10:29 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -2.3\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\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 FRi3YozE78Vc for <notmuch@notmuchmail.org>;\r
16         Thu, 31 Jul 2014 19:10:23 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-6.mit.edu (dmz-mailsec-scanner-6.mit.edu\r
18         [18.7.68.35])\r
19         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id AC54A431FC0\r
22         for <notmuch@notmuchmail.org>; Thu, 31 Jul 2014 19:10:12 -0700 (PDT)\r
23 X-AuditID: 12074423-f79bf6d000007580-d8-53daf7042ee8\r
24 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
25         (using TLS with cipher AES256-SHA (256/256 bits))\r
26         (Client did not present a certificate)\r
27         by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
28         id D1.55.30080.407FAD35; Thu, 31 Jul 2014 22:10:12 -0400 (EDT)\r
29 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
30         by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id s712A98o007827; \r
31         Thu, 31 Jul 2014 22:10:10 -0400\r
32 Received: from drake.dyndns.org\r
33         (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
34         [216.15.114.40]) (authenticated bits=0)\r
35         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
36         by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s712A74O029993\r
37         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
38         Thu, 31 Jul 2014 22:10:09 -0400\r
39 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
40         (envelope-from <amdragon@mit.edu>)\r
41         id 1XD2II-00033y-8R; Thu, 31 Jul 2014 22:10:06 -0400\r
42 From: Austin Clements <amdragon@MIT.EDU>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH v3 12/13] lib: Return an error from operations that require an\r
45         upgrade\r
46 Date: Thu, 31 Jul 2014 22:10:02 -0400\r
47 Message-Id: <1406859003-11561-13-git-send-email-amdragon@mit.edu>\r
48 X-Mailer: git-send-email 2.0.0\r
49 In-Reply-To: <1406859003-11561-1-git-send-email-amdragon@mit.edu>\r
50 References: <1406859003-11561-1-git-send-email-amdragon@mit.edu>\r
51 X-Brightmail-Tracker:\r
52  H4sIAAAAAAAAA+NgFtrFIsWRmVeSWpSXmKPExsUixG6nosvy/VawwYyJMhar5/JYXL85k9mB\r
53         yWPnrLvsHs9W3WIOYIrisklJzcksSy3St0vgyjj7eBtrwQ3tisYna5gbGJtVuhg5OSQETCQu\r
54         zjnPCmGLSVy4t54NxBYSmM0k8eqUWxcjF5C9kVGiYedWNgjnDpPE3R1HWSGcuYwSizd/BGth\r
55         E9CQ2LZ/OSOILSIgLbHz7mywscwCjhKf9y8CqxEWCJPo+vWZvYuRg4NFQFXi/lpbEJMXqOTV\r
56         KgeII+QkGm58AqvmBAr//7eAFeIgB4nW01uZJzDyL2BkWMUom5JbpZubmJlTnJqsW5ycmJeX\r
57         WqRrppebWaKXmlK6iREcRC7KOxj/HFQ6xCjAwajEwzsj/FawEGtiWXFl7iFGSQ4mJVFem49A\r
58         Ib6k/JTKjMTijPii0pzU4kOMEhzMSiK8Lz8A5XhTEiurUovyYVLSHCxK4rxvra2ChQTSE0tS\r
59         s1NTC1KLYLIyHBxKErxnvgI1ChalpqdWpGXmlCCkmTg4QYbzAA2/BlLDW1yQmFucmQ6RP8Wo\r
60         KCXOuwckIQCSyCjNg+uFRfkrRnGgV4R5H4JU8QATBFz3K6DBTECDn9+6DjK4JBEhJdXAaOiW\r
61         d33xoZiC4A+PT6hb/TjwzmR3V/nMA7+eRxlvj4jde5uPt4R3slGeqamPUdHU10cfrvj07vuZ\r
62         +fV30sJlWeWea6yW++rw2+zc5wONoStMDm5aackq+Px50rKYVbULzLUXvZ6xPdvbr0Hez0kk\r
63         Y8Kcltldi9XTkktOsRcz2lwo49w+YVO6sBJLcUaioRZzUXEiAG+P/3bNAgAA\r
64 X-BeenThere: notmuch@notmuchmail.org\r
65 X-Mailman-Version: 2.1.13\r
66 Precedence: list\r
67 List-Id: "Use and development of the notmuch mail system."\r
68         <notmuch.notmuchmail.org>\r
69 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
70         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
71 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
72 List-Post: <mailto:notmuch@notmuchmail.org>\r
73 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
74 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
75         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
76 X-List-Received-Date: Fri, 01 Aug 2014 02:10:30 -0000\r
77 \r
78 Previously, there was no protection against a caller invoking an\r
79 operation on an old database version that would effectively corrupt\r
80 the database by treating it like a newer version.\r
81 \r
82 According to notmuch.h, any caller that opens the database in\r
83 read/write mode is supposed to check if the database needs upgrading\r
84 and perform an upgrade if it does.  This would protect against this,\r
85 but nobody (even the CLI) actually does this.\r
86 \r
87 However, with features, it's easy to protect against incompatible\r
88 operations on a fine-grained basis.  This lightweight change allows\r
89 callers to safely operate on old database versions, while preventing\r
90 specific operations that would corrupt the database with an\r
91 informative error message.\r
92 ---\r
93  lib/database.cc  |  5 +++++\r
94  lib/directory.cc |  5 +++++\r
95  lib/message.cc   |  8 ++++++++\r
96  lib/notmuch.h    | 16 ++++++++++++++++\r
97  4 files changed, 34 insertions(+)\r
98 \r
99 diff --git a/lib/database.cc b/lib/database.cc\r
100 index 04b3790..d90a924 100644\r
101 --- a/lib/database.cc\r
102 +++ b/lib/database.cc\r
103 @@ -310,6 +310,8 @@ notmuch_status_to_string (notmuch_status_t status)\r
104         return "Unbalanced number of calls to notmuch_database_begin_atomic/end_atomic";\r
105      case NOTMUCH_STATUS_UNSUPPORTED_OPERATION:\r
106         return "Unsupported operation";\r
107 +    case NOTMUCH_STATUS_UPGRADE_REQUIRED:\r
108 +       return "Operation requires a database upgrade";\r
109      default:\r
110      case NOTMUCH_STATUS_LAST_STATUS:\r
111         return "Unknown error status value";\r
112 @@ -2219,6 +2221,9 @@ notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,\r
113      if (message_ret == NULL)\r
114         return NOTMUCH_STATUS_NULL_POINTER;\r
115  \r
116 +    if (! (notmuch->features & NOTMUCH_FEATURE_FILE_TERMS))\r
117 +       return NOTMUCH_STATUS_UPGRADE_REQUIRED;\r
118 +\r
119      /* return NULL on any failure */\r
120      *message_ret = NULL;\r
121  \r
122 diff --git a/lib/directory.cc b/lib/directory.cc\r
123 index 6a3ffed..8daaec8 100644\r
124 --- a/lib/directory.cc\r
125 +++ b/lib/directory.cc\r
126 @@ -105,6 +105,11 @@ _notmuch_directory_create (notmuch_database_t *notmuch,\r
127      const char *db_path;\r
128      notmuch_bool_t create = (flags & NOTMUCH_FIND_CREATE);\r
129  \r
130 +    if (! (notmuch->features & NOTMUCH_FEATURE_DIRECTORY_DOCS)) {\r
131 +       *status_ret = NOTMUCH_STATUS_UPGRADE_REQUIRED;\r
132 +       return NULL;\r
133 +    }\r
134 +\r
135      *status_ret = NOTMUCH_STATUS_SUCCESS;\r
136  \r
137      path = _notmuch_database_relative_path (notmuch, path);\r
138 diff --git a/lib/message.cc b/lib/message.cc\r
139 index 4fc427f..1618e81 100644\r
140 --- a/lib/message.cc\r
141 +++ b/lib/message.cc\r
142 @@ -653,6 +653,10 @@ _notmuch_message_add_filename (notmuch_message_t *message,\r
143      if (filename == NULL)\r
144         INTERNAL_ERROR ("Message filename cannot be NULL.");\r
145  \r
146 +    if (! (message->notmuch->features & NOTMUCH_FEATURE_FILE_TERMS) ||\r
147 +       ! (message->notmuch->features & NOTMUCH_FEATURE_BOOL_FOLDER))\r
148 +       return NOTMUCH_STATUS_UPGRADE_REQUIRED;\r
149 +\r
150      relative = _notmuch_database_relative_path (message->notmuch, filename);\r
151  \r
152      status = _notmuch_database_split_path (local, relative, &directory, NULL);\r
153 @@ -697,6 +701,10 @@ _notmuch_message_remove_filename (notmuch_message_t *message,\r
154      notmuch_private_status_t private_status;\r
155      notmuch_status_t status;\r
156  \r
157 +    if (! (message->notmuch->features & NOTMUCH_FEATURE_FILE_TERMS) ||\r
158 +       ! (message->notmuch->features & NOTMUCH_FEATURE_BOOL_FOLDER))\r
159 +       return NOTMUCH_STATUS_UPGRADE_REQUIRED;\r
160 +\r
161      status = _notmuch_database_filename_to_direntry (\r
162         local, message->notmuch, filename, NOTMUCH_FIND_LOOKUP, &direntry);\r
163      if (status || !direntry)\r
164 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
165 index 3c5ec98..cbf2ba5 100644\r
166 --- a/lib/notmuch.h\r
167 +++ b/lib/notmuch.h\r
168 @@ -160,6 +160,10 @@ typedef enum _notmuch_status {\r
169       */\r
170      NOTMUCH_STATUS_UNSUPPORTED_OPERATION,\r
171      /**\r
172 +     * The operation requires a database upgrade.\r
173 +     */\r
174 +    NOTMUCH_STATUS_UPGRADE_REQUIRED,\r
175 +    /**\r
176       * Not an actual status value. Just a way to find out how many\r
177       * valid status values there are.\r
178       */\r
179 @@ -438,6 +442,9 @@ notmuch_database_end_atomic (notmuch_database_t *notmuch);\r
180   *\r
181   * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred;\r
182   *     directory not retrieved.\r
183 + *\r
184 + * NOTMUCH_STATUS_UPGRADE_REQUIRED: The caller must upgrade the\r
185 + *     database to use this function.\r
186   */\r
187  notmuch_status_t\r
188  notmuch_database_get_directory (notmuch_database_t *database,\r
189 @@ -490,6 +497,9 @@ notmuch_database_get_directory (notmuch_database_t *database,\r
190   *\r
191   * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only\r
192   *     mode so no message can be added.\r
193 + *\r
194 + * NOTMUCH_STATUS_UPGRADE_REQUIRED: The caller must upgrade the\r
195 + *     database to use this function.\r
196   */\r
197  notmuch_status_t\r
198  notmuch_database_add_message (notmuch_database_t *database,\r
199 @@ -520,6 +530,9 @@ notmuch_database_add_message (notmuch_database_t *database,\r
200   *\r
201   * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only\r
202   *     mode so no message can be removed.\r
203 + *\r
204 + * NOTMUCH_STATUS_UPGRADE_REQUIRED: The caller must upgrade the\r
205 + *     database to use this function.\r
206   */\r
207  notmuch_status_t\r
208  notmuch_database_remove_message (notmuch_database_t *database,\r
209 @@ -575,6 +588,9 @@ notmuch_database_find_message (notmuch_database_t *database,\r
210   * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory, creating the message object\r
211   *\r
212   * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred\r
213 + *\r
214 + * NOTMUCH_STATUS_UPGRADE_REQUIRED: The caller must upgrade the\r
215 + *     database to use this function.\r
216   */\r
217  notmuch_status_t\r
218  notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,\r
219 -- \r
220 2.0.0\r
221 \r