Re: Deduplication ?
[notmuch-archives.git] / 7a / 81ce25e253ad15005fe9a3b2fdb3334a5798b4
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 376E3429E47\r
6         for <notmuch@notmuchmail.org>; Mon, 30 Apr 2012 09:25:48 -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 T1DyEDjCiaEJ for <notmuch@notmuchmail.org>;\r
16         Mon, 30 Apr 2012 09:25:47 -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 60925429E3E\r
20         for <notmuch@notmuchmail.org>; Mon, 30 Apr 2012 09:25:45 -0700 (PDT)\r
21 X-AuditID: 12074422-b7fd66d0000008f9-91-4f9ebd0805e6\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 44.AF.02297.80DBE9F4; Mon, 30 Apr 2012 12:25:44 -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 q3UGPhSm001281; \r
27         Mon, 30 Apr 2012 12:25:43 -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 q3UGPgXS005256\r
33         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
34         Mon, 30 Apr 2012 12:25:43 -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 1SOtPx-0006H7-KB; Mon, 30 Apr 2012 12:25:41 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH v2 2/6] lib/cli: Make notmuch_database_create return a status\r
41         code\r
42 Date: Mon, 30 Apr 2012 12:25:34 -0400\r
43 Message-Id: <1335803138-24024-3-git-send-email-amdragon@mit.edu>\r
44 X-Mailer: git-send-email 1.7.9.1\r
45 In-Reply-To: <1335803138-24024-1-git-send-email-amdragon@mit.edu>\r
46 References: <1335651473-19652-1-git-send-email-amdragon@mit.edu>\r
47         <1335803138-24024-1-git-send-email-amdragon@mit.edu>\r
48 X-Brightmail-Tracker:\r
49  H4sIAAAAAAAAA+NgFtrMIsWRmVeSWpSXmKPExsUixG6nrsuxd56/wZwFOhbXb85kdmD0eLbq\r
50         FnMAYxSXTUpqTmZZapG+XQJXxs51R1kLfitWtHWfZW1g/CTVxcjJISFgIvF4dy8rhC0mceHe\r
51         erYuRi4OIYF9jBJr2t9AORsYJdoP/mGFcO4zSVz+dA3Kmc8o8alzCjtIP5uAhsS2/csZQWwR\r
52         AWmJnXdnAxVxcDALqEn86VIBCQsLBEl8PPoIrIRFQFVi1vWVTCA2r4CDxM7LbewQZyhIPFt3\r
53         HCzOKeAocevANxYQW0igXGLjhU+MExj5FzAyrGKUTcmt0s1NzMwpTk3WLU5OzMtLLdI11cvN\r
54         LNFLTSndxAgOGxelHYw/DyodYhTgYFTi4X2xcJ6/EGtiWXFl7iFGSQ4mJVFe3T1AIb6k/JTK\r
55         jMTijPii0pzU4kOMEhzMSiK8pROBcrwpiZVVqUX5MClpDhYlcV51rXd+QgLpiSWp2ampBalF\r
56         MFkZDg4lCV57kKGCRanpqRVpmTklCGkmDk6Q4TxAw8FqeIsLEnOLM9Mh8qcYFaXEeRNBEgIg\r
57         iYzSPLheWFy/YhQHekWYNxCkigeYEuC6XwENZgIanG8ONrgkESEl1cBoGJe+9l6awI0WiXTu\r
58         cudfyismSEQ/NkvWPRuZW3Zyiaq579Ztb/uvsBnlXm1iCgrZ5Vb4ev/NOkn1hXONnRhUGLtO\r
59         K15btjc83J5znWUsZ8Pb16c6wnltHT45l766+uQvb+WWG+/veO8IUi5hCWj1MYw6e0qWmSX7\r
60         +fOml2ozRCLUROJieJRYijMSDbWYi4oTAYrH6Y/GAgAA\r
61 X-BeenThere: notmuch@notmuchmail.org\r
62 X-Mailman-Version: 2.1.13\r
63 Precedence: list\r
64 List-Id: "Use and development of the notmuch mail system."\r
65         <notmuch.notmuchmail.org>\r
66 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
68 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
69 List-Post: <mailto:notmuch@notmuchmail.org>\r
70 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
71 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
72         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
73 X-List-Received-Date: Mon, 30 Apr 2012 16:25:48 -0000\r
74 \r
75 This is the notmuch_database_create equivalent of the previous change.\r
76 \r
77 In this case, there were places where errors were not being propagated\r
78 correctly in notmuch_database_create or in calls to it.  These have\r
79 been fixed, using the new status value.\r
80 ---\r
81  lib/database.cc |   29 ++++++++++++++++++++++-------\r
82  lib/notmuch.h   |   22 ++++++++++++++++++----\r
83  notmuch-new.c   |    3 ++-\r
84  3 files changed, 42 insertions(+), 12 deletions(-)\r
85 \r
86 diff --git a/lib/database.cc b/lib/database.cc\r
87 index 1e66599..07f186e 100644\r
88 --- a/lib/database.cc\r
89 +++ b/lib/database.cc\r
90 @@ -520,9 +520,10 @@ parse_references (void *ctx,\r
91      }\r
92  }\r
93  \r
94 -notmuch_database_t *\r
95 -notmuch_database_create (const char *path)\r
96 +notmuch_status_t\r
97 +notmuch_database_create (const char *path, notmuch_database_t **database)\r
98  {\r
99 +    notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
100      notmuch_database_t *notmuch = NULL;\r
101      char *notmuch_path = NULL;\r
102      struct stat st;\r
103 @@ -530,6 +531,7 @@ notmuch_database_create (const char *path)\r
104  \r
105      if (path == NULL) {\r
106         fprintf (stderr, "Error: Cannot create a database for a NULL path.\n");\r
107 +       status = NOTMUCH_STATUS_NULL_POINTER;\r
108         goto DONE;\r
109      }\r
110  \r
111 @@ -537,12 +539,14 @@ notmuch_database_create (const char *path)\r
112      if (err) {\r
113         fprintf (stderr, "Error: Cannot create database at %s: %s.\n",\r
114                  path, strerror (errno));\r
115 +       status = NOTMUCH_STATUS_FILE_ERROR;\r
116         goto DONE;\r
117      }\r
118  \r
119      if (! S_ISDIR (st.st_mode)) {\r
120         fprintf (stderr, "Error: Cannot create database at %s: Not a directory.\n",\r
121                  path);\r
122 +       status = NOTMUCH_STATUS_FILE_ERROR;\r
123         goto DONE;\r
124      }\r
125  \r
126 @@ -553,19 +557,30 @@ notmuch_database_create (const char *path)\r
127      if (err) {\r
128         fprintf (stderr, "Error: Cannot create directory %s: %s.\n",\r
129                  notmuch_path, strerror (errno));\r
130 +       status = NOTMUCH_STATUS_FILE_ERROR;\r
131         goto DONE;\r
132      }\r
133  \r
134 -    notmuch_database_open (path,\r
135 -                          NOTMUCH_DATABASE_MODE_READ_WRITE,\r
136 -                          &notmuch);\r
137 -    notmuch_database_upgrade (notmuch, NULL, NULL);\r
138 +    status = notmuch_database_open (path,\r
139 +                                   NOTMUCH_DATABASE_MODE_READ_WRITE,\r
140 +                                   &notmuch);\r
141 +    if (status)\r
142 +       goto DONE;\r
143 +    status = notmuch_database_upgrade (notmuch, NULL, NULL);\r
144 +    if (status) {\r
145 +       notmuch_database_close(notmuch);\r
146 +       notmuch = NULL;\r
147 +    }\r
148  \r
149    DONE:\r
150      if (notmuch_path)\r
151         talloc_free (notmuch_path);\r
152  \r
153 -    return notmuch;\r
154 +    if (database)\r
155 +       *database = notmuch;\r
156 +    else\r
157 +       talloc_free (notmuch);\r
158 +    return status;\r
159  }\r
160  \r
161  notmuch_status_t\r
162 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
163 index 44b0c46..e6e5cc2 100644\r
164 --- a/lib/notmuch.h\r
165 +++ b/lib/notmuch.h\r
166 @@ -140,11 +140,25 @@ typedef struct _notmuch_filenames notmuch_filenames_t;\r
167   * contained within 'path' can be added to the database by calling\r
168   * notmuch_database_add_message.\r
169   *\r
170 - * In case of any failure, this function returns NULL, (after printing\r
171 - * an error message on stderr).\r
172 + * In case of any failure, this function returns an error status and\r
173 + * sets *database to NULL (after printing an error message on stderr).\r
174 + *\r
175 + * Return value:\r
176 + *\r
177 + * NOTMUCH_STATUS_SUCCESS: Successfully created the database.\r
178 + *\r
179 + * NOTMUCH_STATUS_NULL_POINTER: The given 'path' argument is NULL.\r
180 + *\r
181 + * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory.\r
182 + *\r
183 + * NOTMUCH_STATUS_FILE_ERROR: An error occurred trying to create the\r
184 + *     database file (such as permission denied, or file not found,\r
185 + *     etc.), or the database already exists.\r
186 + *\r
187 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred.\r
188   */\r
189 -notmuch_database_t *\r
190 -notmuch_database_create (const char *path);\r
191 +notmuch_status_t\r
192 +notmuch_database_create (const char *path, notmuch_database_t **database);\r
193  \r
194  typedef enum {\r
195      NOTMUCH_DATABASE_MODE_READ_ONLY = 0,\r
196 diff --git a/notmuch-new.c b/notmuch-new.c\r
197 index 7788743..cb720cc 100644\r
198 --- a/notmuch-new.c\r
199 +++ b/notmuch-new.c\r
200 @@ -900,7 +900,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
201             return 1;\r
202  \r
203         printf ("Found %d total files (that's not much mail).\n", count);\r
204 -       notmuch = notmuch_database_create (db_path);\r
205 +       if (notmuch_database_create (db_path, &notmuch))\r
206 +           return 1;\r
207         add_files_state.total_files = count;\r
208      } else {\r
209         if (notmuch_database_open (db_path, NOTMUCH_DATABASE_MODE_READ_WRITE,\r
210 -- \r
211 1.7.9.1\r
212 \r