Re: [PATCH v2] Omit User-Agent: header by default
[notmuch-archives.git] / e1 / 9720e70f6e08441a44516650017dbe1a6acf8e
1 Return-Path: <amthrax@drake.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 D95CE431FCB\r
6         for <notmuch@notmuchmail.org>; Sun, 13 May 2012 12:57:24 -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: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 ufcnFKicvW9i for <notmuch@notmuchmail.org>;\r
16         Sun, 13 May 2012 12:57:23 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU\r
18         [18.7.68.34])\r
19         by olra.theworths.org (Postfix) with ESMTP id EF138431FC3\r
20         for <notmuch@notmuchmail.org>; Sun, 13 May 2012 12:57:22 -0700 (PDT)\r
21 X-AuditID: 12074422-b7fd66d0000008f9-a7-4fb012227241\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 75.24.02297.22210BF4; Sun, 13 May 2012 15:57:22 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q4DJvKsJ023343; \r
27         Sun, 13 May 2012 15:57:20 -0400\r
28 Received: from drake.mit.edu\r
29         (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
30         [209.6.116.242]) (authenticated bits=0)\r
31         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
32         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q4DJvF49022907\r
33         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
34         Sun, 13 May 2012 15:57:16 -0400 (EDT)\r
35 Received: from amthrax by drake.mit.edu with local (Exim 4.77)\r
36         (envelope-from <amthrax@drake.mit.edu>)\r
37         id 1STeup-0003en-L8; Sun, 13 May 2012 15:57:15 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH 1/5] lib/cli: Make notmuch_database_get_directory return a\r
41         status code\r
42 Date: Sun, 13 May 2012 15:57:05 -0400\r
43 Message-Id: <1336939029-13969-2-git-send-email-amdragon@mit.edu>\r
44 X-Mailer: git-send-email 1.7.10\r
45 In-Reply-To: <1336939029-13969-1-git-send-email-amdragon@mit.edu>\r
46 References: <1336939029-13969-1-git-send-email-amdragon@mit.edu>\r
47 X-Brightmail-Tracker:\r
48  H4sIAAAAAAAAA+NgFrrNIsWRmVeSWpSXmKPExsUixG6nrqsktMHfoPuTiMXs1h9MFjdauxkt\r
49         mqY7W1y/OZPZ4s3KeawOrB6Hvy5k8Zh4/jSbx637r9k9nq26xeyx5dB75gDWKC6blNSczLLU\r
50         In27BK6MxsNOBTcMK65ffMbUwNiq0cXIySEhYCKxoekHG4QtJnHh3nogm4tDSGAfo8SfyW9Z\r
51         IJwNjBILV05lgnDuM0lMvriBEcKZzygx89hBsH42AQ2JbfuXM4LYIgLSEjvvzmYFKWIW6GKU\r
52         +P2mmRkkISwQJrH8RwtYEYuAqkTvrf1gcV4BB4mTD9qZIQ6Rl3h6vw9sKKeAo8SyKwvB4kIg\r
53         NR//Mk9g5F/AyLCKUTYlt0o3NzEzpzg1Wbc4OTEvL7VI11QvN7NELzWldBMjOAxdlHYw/jyo\r
54         dIhRgINRiYd3geh6fyHWxLLiytxDjJIcTEqivGmCG/yF+JLyUyozEosz4otKc1KLDzFKcDAr\r
55         ifCufwhUzpuSWFmVWpQPk5LmYFES51XXeucnJJCeWJKanZpakFoEk5Xh4FCS4M0FGSpYlJqe\r
56         WpGWmVOCkGbi4AQZzgM0PAWkhre4IDG3ODMdIn+KUVFKHKJZACSRUZoH1wtLE68YxYFeEeZt\r
57         BKniAaYYuO5XQIOZgAbzC6wDGVySiJCSamCcpN9tbxvyYLLKsr4Vh8VOiaxz6p3JsePzZAcO\r
58         T9+1TPZ7Fmht+S+62+9Xy/s/V1lbnt1qmLukL9W5xmr2xuiXew7Wf3tXk8T5qu5nuP1URtav\r
59         CxOESme3lf65MUugZ+f5xX+0D4v2qT9NUWs5OOfkxaaKuHNyfe/np8sbP/Lh0FVsn12T+6VI\r
60         iaU4I9FQi7moOBEAKnU/+u4CAAA=\r
61 Cc: tomi.ollila@iki.fi\r
62 X-BeenThere: notmuch@notmuchmail.org\r
63 X-Mailman-Version: 2.1.13\r
64 Precedence: list\r
65 List-Id: "Use and development of the notmuch mail system."\r
66         <notmuch.notmuchmail.org>\r
67 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
68         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
69 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
70 List-Post: <mailto:notmuch@notmuchmail.org>\r
71 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
72 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
73         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
74 X-List-Received-Date: Sun, 13 May 2012 19:57:25 -0000\r
75 \r
76 Previously, notmuch_database_get_directory had no way to indicate how\r
77 it had failed.  This changes its prototype to return a status code and\r
78 set an out-argument to the retrieved directory, like similar functions\r
79 in the library API.  This does *not* change its currently broken\r
80 behavior of creating directory objects when they don't exist, but it\r
81 does document it and paves the way for fixing this.  Also, it can now\r
82 check for a read-only database and return\r
83 NOTMUCH_STATUS_READ_ONLY_DATABASE instead of crashing.\r
84 \r
85 In the interest of atomicity, this also updates calls from the CLI so\r
86 that notmuch still compiles.\r
87 ---\r
88  lib/database.cc |   22 ++++++++++++++++------\r
89  lib/notmuch.h   |   24 +++++++++++++++++++++---\r
90  notmuch-new.c   |   21 ++++++++++++++-------\r
91  3 files changed, 51 insertions(+), 16 deletions(-)\r
92 \r
93 diff --git a/lib/database.cc b/lib/database.cc\r
94 index 07f186e..f8c4a7d 100644\r
95 --- a/lib/database.cc\r
96 +++ b/lib/database.cc\r
97 @@ -955,8 +955,8 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
98                 mtime = Xapian::sortable_unserialise (\r
99                     document.get_value (NOTMUCH_VALUE_TIMESTAMP));\r
100  \r
101 -               directory = notmuch_database_get_directory (notmuch,\r
102 -                                                           term.c_str() + 10);\r
103 +               directory = _notmuch_directory_create (notmuch, term.c_str() + 10,\r
104 +                                                      &status);\r
105                 notmuch_directory_set_mtime (directory, mtime);\r
106                 notmuch_directory_destroy (directory);\r
107             }\r
108 @@ -1304,20 +1304,30 @@ _notmuch_database_relative_path (notmuch_database_t *notmuch,\r
109      return relative;\r
110  }\r
111  \r
112 -notmuch_directory_t *\r
113 +notmuch_status_t\r
114  notmuch_database_get_directory (notmuch_database_t *notmuch,\r
115 -                               const char *path)\r
116 +                               const char *path,\r
117 +                               notmuch_directory_t **directory)\r
118  {\r
119      notmuch_status_t status;\r
120  \r
121 +    if (directory == NULL)\r
122 +       return NOTMUCH_STATUS_NULL_POINTER;\r
123 +    *directory = NULL;\r
124 +\r
125 +    /* XXX Handle read-only databases properly */\r
126 +    if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)\r
127 +       return NOTMUCH_STATUS_READ_ONLY_DATABASE;\r
128 +\r
129      try {\r
130 -       return _notmuch_directory_create (notmuch, path, &status);\r
131 +       *directory = _notmuch_directory_create (notmuch, path, &status);\r
132      } catch (const Xapian::Error &error) {\r
133         fprintf (stderr, "A Xapian exception occurred getting directory: %s.\n",\r
134                  error.get_msg().c_str());\r
135         notmuch->exception_reported = TRUE;\r
136 -       return NULL;\r
137 +       status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
138      }\r
139 +    return status;\r
140  }\r
141  \r
142  /* Allocate a document ID that satisfies the following criteria:\r
143 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
144 index e6e5cc2..d414198 100644\r
145 --- a/lib/notmuch.h\r
146 +++ b/lib/notmuch.h\r
147 @@ -300,11 +300,29 @@ notmuch_database_end_atomic (notmuch_database_t *notmuch);\r
148   * (see notmuch_database_get_path), or else should be an absolute path\r
149   * with initial components that match the path of 'database'.\r
150   *\r
151 - * Can return NULL if a Xapian exception occurs.\r
152 + * Note: Currently this will create the directory object if it doesn't\r
153 + * exist.  This is not intentional behavior and is likely to change in\r
154 + * the near future.  To future-proof, when this returns\r
155 + * NOTMUCH_STATUS_SUCCESS, callers should check that *directory is not\r
156 + * NULL.\r
157 + *\r
158 + * Return value:\r
159 + *\r
160 + * NOTMUCH_STATUS_SUCCESS: Successfully retrieved directory.\r
161 + *\r
162 + * NOTMUCH_STATUS_NULL_POINTER: The given 'directory' argument is NULL.\r
163 + *\r
164 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred;\r
165 + *     directory not retrieved.\r
166 + *\r
167 + * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only\r
168 + *     mode so the directory cannot be created (this case will be\r
169 + *     removed in the future).\r
170   */\r
171 -notmuch_directory_t *\r
172 +notmuch_status_t\r
173  notmuch_database_get_directory (notmuch_database_t *database,\r
174 -                               const char *path);\r
175 +                               const char *path,\r
176 +                               notmuch_directory_t **directory);\r
177  \r
178  /* Add a new message to the given notmuch database or associate an\r
179   * additional filename with an existing message.\r
180 diff --git a/notmuch-new.c b/notmuch-new.c\r
181 index cb720cc..a3a8bec 100644\r
182 --- a/notmuch-new.c\r
183 +++ b/notmuch-new.c\r
184 @@ -250,7 +250,7 @@ add_files_recursive (notmuch_database_t *notmuch,\r
185      notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;\r
186      notmuch_message_t *message = NULL;\r
187      struct dirent **fs_entries = NULL;\r
188 -    int i, num_fs_entries;\r
189 +    int i, num_fs_entries = 0;\r
190      notmuch_directory_t *directory;\r
191      notmuch_filenames_t *db_files = NULL;\r
192      notmuch_filenames_t *db_subdirs = NULL;\r
193 @@ -274,8 +274,12 @@ add_files_recursive (notmuch_database_t *notmuch,\r
194  \r
195      fs_mtime = st.st_mtime;\r
196  \r
197 -    directory = notmuch_database_get_directory (notmuch, path);\r
198 -    db_mtime = notmuch_directory_get_mtime (directory);\r
199 +    status = notmuch_database_get_directory (notmuch, path, &directory);\r
200 +    if (status) {\r
201 +       ret = status;\r
202 +       goto DONE;\r
203 +    }\r
204 +    db_mtime = directory ? notmuch_directory_get_mtime (directory) : 0;\r
205  \r
206      new_directory = db_mtime ? FALSE : TRUE;\r
207  \r
208 @@ -295,7 +299,7 @@ add_files_recursive (notmuch_database_t *notmuch,\r
209       * by a new out-argument, or by recording this information and\r
210       * providing an accessor.\r
211       */\r
212 -    if (new_directory)\r
213 +    if (new_directory && directory)\r
214         notmuch_directory_set_mtime (directory, -1);\r
215  \r
216      /* If the database knows about this directory, then we sort based\r
217 @@ -810,7 +814,9 @@ _remove_directory (void *ctx,\r
218      notmuch_filenames_t *files, *subdirs;\r
219      char *absolute;\r
220  \r
221 -    directory = notmuch_database_get_directory (notmuch, path);\r
222 +    status = notmuch_database_get_directory (notmuch, path, &directory);\r
223 +    if (status || !directory)\r
224 +       return status;\r
225  \r
226      for (files = notmuch_directory_get_child_files (directory);\r
227          notmuch_filenames_valid (files);\r
228 @@ -981,9 +987,10 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
229      }\r
230  \r
231      for (f = add_files_state.directory_mtimes->head; f && !interrupted; f = f->next) {\r
232 +       notmuch_status_t status;\r
233         notmuch_directory_t *directory;\r
234 -       directory = notmuch_database_get_directory (notmuch, f->filename);\r
235 -       if (directory) {\r
236 +       status = notmuch_database_get_directory (notmuch, f->filename, &directory);\r
237 +       if (status == NOTMUCH_STATUS_SUCCESS && directory) {\r
238             notmuch_directory_set_mtime (directory, f->mtime);\r
239             notmuch_directory_destroy (directory);\r
240         }\r
241 -- \r
242 1.7.10\r
243 \r