[PATCH 1/9] lib: read "property" terms from messages.
[notmuch-archives.git] / 3e / 2b7d7bfccca3378fa6586ae1d3c2e68ea6762f
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 DB3CE431FB6\r
6         for <notmuch@notmuchmail.org>; Sat, 28 Apr 2012 15:18:00 -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 KBC305-39tM6 for <notmuch@notmuchmail.org>;\r
16         Sat, 28 Apr 2012 15:17:59 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU\r
18         [18.9.25.13])\r
19         by olra.theworths.org (Postfix) with ESMTP id A4EEA431FAF\r
20         for <notmuch@notmuchmail.org>; Sat, 28 Apr 2012 15:17:59 -0700 (PDT)\r
21 X-AuditID: 1209190d-b7fbf6d0000008ba-5f-4f9c6c9790fe\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
23         by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id BB.B8.02234.79C6C9F4; Sat, 28 Apr 2012 18:17:59 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q3SMHw6Q029824; \r
27         Sat, 28 Apr 2012 18:17:58 -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 q3SMHvw1008919\r
33         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
34         Sat, 28 Apr 2012 18:17:58 -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 1SOFxl-00058G-3R; Sat, 28 Apr 2012 18:17:57 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH 2/6] lib/cli: Make notmuch_database_create return a status\r
41  code\r
42 Date: Sat, 28 Apr 2012 18:17:49 -0400\r
43 Message-Id: <1335651473-19652-3-git-send-email-amdragon@mit.edu>\r
44 X-Mailer: git-send-email 1.7.9.1\r
45 In-Reply-To: <1335651473-19652-1-git-send-email-amdragon@mit.edu>\r
46 References: <1335651473-19652-1-git-send-email-amdragon@mit.edu>\r
47 X-Brightmail-Tracker:\r
48  H4sIAAAAAAAAA+NgFtrEIsWRmVeSWpSXmKPExsUixCmqrDs9Z46/wZNlghbXb85kdmD0eLbq\r
49         FnMAYxSXTUpqTmZZapG+XQJXxqyWO2wFV2Qrju19ztrAuFG8i5GTQ0LARGLB0gssELaYxIV7\r
50         69m6GLk4hAT2MUq837yXHcLZwCjx+PQNJpAqIYH7TBJtS7QhEvMZJfat/MsKkmAT0JDYtn85\r
51         I4gtIiAtsfPubKA4BwezgJrEny4VkLCwgL/Eoj8rmEFsFgFViYX/zoG18go4SLx+dogZ4goF\r
52         iWfrjoPt4hRwlPi/+QQ7xF4HiY55E9gmMPIvYGRYxSibklulm5uYmVOcmqxbnJyYl5dapGuk\r
53         l5tZopeaUrqJERw0krw7GN8dVDrEKMDBqMTDe2j9LH8h1sSy4srcQ4ySHExKorwsWXP8hfiS\r
54         8lMqMxKLM+KLSnNSiw8xSnAwK4nwaosD5XhTEiurUovyYVLSHCxK4ryqWu/8hATSE0tSs1NT\r
55         C1KLYLIyHBxKErxHs4EaBYtS01Mr0jJzShDSTBycIMN5gIbvAanhLS5IzC3OTIfIn2JUlBLn\r
56         XQ+SEABJZJTmwfXCovoVozjQK8K8Z0GqeIAJAa77FdBgJqDBTJ6zQAaXJCKkpBoYHVyFJVbr\r
57         +u+a9DYvoy1dTHt7XlPF3JebLj+Z2vLKcWupmf5Zhudvp20vmu9t9ORbpfMc0wsPg8oPZa3h\r
58         ZT+WEfozSFP7VpFwn+RytwaViC1z1VeZZxU+1Dz+d6u82FUDI+MYTavZuZO+vyh9U2ZSrPS9\r
59         e269gvvKM0l/7tbr/1n85pGTgsoGJZbijERDLeai4kQAETauQ8UCAAA=\r
60 X-BeenThere: notmuch@notmuchmail.org\r
61 X-Mailman-Version: 2.1.13\r
62 Precedence: list\r
63 List-Id: "Use and development of the notmuch mail system."\r
64         <notmuch.notmuchmail.org>\r
65 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
66         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
67 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
68 List-Post: <mailto:notmuch@notmuchmail.org>\r
69 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
70 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
71         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
72 X-List-Received-Date: Sat, 28 Apr 2012 22:18:01 -0000\r
73 \r
74 This is the notmuch_database_create equivalent of the previous change.\r
75 \r
76 In this case, there were places where errors were not being propagated\r
77 correctly in notmuch_database_create or in calls to it.  These have\r
78 been fixed, using the new status value.\r
79 ---\r
80  lib/database.cc |   26 +++++++++++++++++++-------\r
81  lib/notmuch.h   |    8 ++++----\r
82  notmuch-new.c   |    3 ++-\r
83  3 files changed, 25 insertions(+), 12 deletions(-)\r
84 \r
85 diff --git a/lib/database.cc b/lib/database.cc\r
86 index a29fe67..a3ae504 100644\r
87 --- a/lib/database.cc\r
88 +++ b/lib/database.cc\r
89 @@ -520,9 +520,10 @@ parse_references (void *ctx,\r
90      }\r
91  }\r
92  \r
93 -notmuch_database_t *\r
94 -notmuch_database_create (const char *path)\r
95 +notmuch_status_t\r
96 +notmuch_database_create (const char *path, notmuch_database_t **database)\r
97  {\r
98 +    notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
99      notmuch_database_t *notmuch = NULL;\r
100      char *notmuch_path = NULL;\r
101      struct stat st;\r
102 @@ -530,6 +531,7 @@ notmuch_database_create (const char *path)\r
103  \r
104      if (path == NULL) {\r
105         fprintf (stderr, "Error: Cannot create a database for a NULL path.\n");\r
106 +       status = NOTMUCH_STATUS_NULL_POINTER;\r
107         goto DONE;\r
108      }\r
109  \r
110 @@ -537,12 +539,14 @@ notmuch_database_create (const char *path)\r
111      if (err) {\r
112         fprintf (stderr, "Error: Cannot create database at %s: %s.\n",\r
113                  path, strerror (errno));\r
114 +       status = NOTMUCH_STATUS_FILE_ERROR;\r
115         goto DONE;\r
116      }\r
117  \r
118      if (! S_ISDIR (st.st_mode)) {\r
119         fprintf (stderr, "Error: Cannot create database at %s: Not a directory.\n",\r
120                  path);\r
121 +       status = NOTMUCH_STATUS_FILE_ERROR;\r
122         goto DONE;\r
123      }\r
124  \r
125 @@ -553,19 +557,27 @@ notmuch_database_create (const char *path)\r
126      if (err) {\r
127         fprintf (stderr, "Error: Cannot create directory %s: %s.\n",\r
128                  notmuch_path, strerror (errno));\r
129 +       status = NOTMUCH_STATUS_FILE_ERROR;\r
130         goto DONE;\r
131      }\r
132  \r
133 -    notmuch_database_open (path,\r
134 -                          NOTMUCH_DATABASE_MODE_READ_WRITE,\r
135 -                          &notmuch);\r
136 -    notmuch_database_upgrade (notmuch, NULL, NULL);\r
137 +    status = notmuch_database_open (path,\r
138 +                                   NOTMUCH_DATABASE_MODE_READ_WRITE,\r
139 +                                   &notmuch);\r
140 +    if (status)\r
141 +       goto DONE;\r
142 +    status = notmuch_database_upgrade (notmuch, NULL, NULL);\r
143 +    if (status) {\r
144 +       notmuch_database_close(notmuch);\r
145 +       notmuch = NULL;\r
146 +    }\r
147  \r
148    DONE:\r
149      if (notmuch_path)\r
150         talloc_free (notmuch_path);\r
151  \r
152 -    return notmuch;\r
153 +    *database = notmuch;\r
154 +    return status;\r
155  }\r
156  \r
157  notmuch_status_t\r
158 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
159 index 8a011f2..d880aeb 100644\r
160 --- a/lib/notmuch.h\r
161 +++ b/lib/notmuch.h\r
162 @@ -140,11 +140,11 @@ typedef struct _notmuch_filenames notmuch_filenames_t;\r
163   * contained within 'path' can be added to the database by calling\r
164   * notmuch_database_add_message.\r
165   *\r
166 - * In case of any failure, this function returns NULL, (after printing\r
167 - * an error message on stderr).\r
168 + * In case of any failure, this function returns an error status and\r
169 + * sets *database to NULL (after printing an error message on stderr).\r
170   */\r
171 -notmuch_database_t *\r
172 -notmuch_database_create (const char *path);\r
173 +notmuch_status_t\r
174 +notmuch_database_create (const char *path, notmuch_database_t **database);\r
175  \r
176  typedef enum {\r
177      NOTMUCH_DATABASE_MODE_READ_ONLY = 0,\r
178 diff --git a/notmuch-new.c b/notmuch-new.c\r
179 index 7788743..cb720cc 100644\r
180 --- a/notmuch-new.c\r
181 +++ b/notmuch-new.c\r
182 @@ -900,7 +900,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
183             return 1;\r
184  \r
185         printf ("Found %d total files (that's not much mail).\n", count);\r
186 -       notmuch = notmuch_database_create (db_path);\r
187 +       if (notmuch_database_create (db_path, &notmuch))\r
188 +           return 1;\r
189         add_files_state.total_files = count;\r
190      } else {\r
191         if (notmuch_database_open (db_path, NOTMUCH_DATABASE_MODE_READ_WRITE,\r
192 -- \r
193 1.7.9.1\r
194 \r