database error
[notmuch-archives.git] / 68 / a66de75faa7052c7e1e2222e99ca8a06267f2c
1 Return-Path: <prvs=4673c7db88=davidben@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 2BE13431FBF\r
6         for <notmuch@notmuchmail.org>; Fri, 26 Feb 2010 15:06:36 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -2.401\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.401 tagged_above=-999 required=5 tests=[AWL=0.198,\r
12         BAYES_00=-2.599] autolearn=ham\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 c2cF4v1xjfKB for <notmuch@notmuchmail.org>;\r
16         Fri, 26 Feb 2010 15:06:35 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU\r
18         [18.7.68.35])\r
19         by olra.theworths.org (Postfix) with ESMTP id ED42D431FAE\r
20         for <notmuch@notmuchmail.org>; Fri, 26 Feb 2010 15:06:34 -0800 (PST)\r
21 X-AuditID: 12074423-b7cebae000000968-bf-4b8853f5c9b8\r
22 Received: from mailhub-auth-2.mit.edu (MAILHUB-AUTH-2.MIT.EDU [18.7.62.36])\r
23         by dmz-mailsec-scanner-6.mit.edu (Symantec Brightmail Gateway) with\r
24         SMTP id 4F.05.02408.5F3588B4; Fri, 26 Feb 2010 18:06:29 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id o1QN6TW8004567; \r
27         Fri, 26 Feb 2010 18:06:29 -0500\r
28 Received: from localhost.localdomain (ET-NINETY-THREE.MIT.EDU [18.208.1.93])\r
29         (authenticated bits=0)\r
30         (User authenticated as davidben@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id o1QN6OeI029491\r
32         (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT);\r
33         Fri, 26 Feb 2010 18:06:29 -0500 (EST)\r
34 From: David Benjamin <davidben@MIT.EDU>\r
35 To: notmuch@notmuchmail.org\r
36 Date: Fri, 26 Feb 2010 18:06:23 -0500\r
37 Message-Id: <1267225583-26096-1-git-send-email-davidben@mit.edu>\r
38 X-Mailer: git-send-email 1.7.0.18.g39b3\r
39 In-Reply-To: <1266978183-19698-4-git-send-email-davidben@mit.edu>\r
40 References: <1266978183-19698-4-git-send-email-davidben@mit.edu>\r
41 X-Brightmail-Tracker: AAAAARMRPew=\r
42 Subject: [notmuch] [PATCH v2 3/4] Configure the database separately from\r
43         mail store\r
44 X-BeenThere: notmuch@notmuchmail.org\r
45 X-Mailman-Version: 2.1.13\r
46 Precedence: list\r
47 List-Id: "Use and development of the notmuch mail system."\r
48         <notmuch.notmuchmail.org>\r
49 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
50         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
51 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
52 List-Post: <mailto:notmuch@notmuchmail.org>\r
53 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
54 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
56 X-List-Received-Date: Fri, 26 Feb 2010 23:06:36 -0000\r
57 \r
58 Signed-off-by: David Benjamin <davidben@mit.edu>\r
59 ---\r
60 \r
61  Apparently I never ran the last-minute tweak I did to\r
62  notmuch_config_set_database_path. Oops. Oh well, here's the trivially fixed\r
63  version.\r
64 \r
65  notmuch-client.h |    7 ++++++\r
66  notmuch-config.c |   62 ++++++++++++++++++++++++++++++++++++++++--------------\r
67  notmuch-new.c    |   14 ++++-------\r
68  3 files changed, 58 insertions(+), 25 deletions(-)\r
69 \r
70 diff --git a/notmuch-client.h b/notmuch-client.h\r
71 index 1a676d2..010fdc7 100644\r
72 --- a/notmuch-client.h\r
73 +++ b/notmuch-client.h\r
74 @@ -148,6 +148,13 @@ void\r
75  notmuch_config_set_database_path (notmuch_config_t *config,\r
76                                   const char *database_path);\r
77  \r
78 +const char *\r
79 +notmuch_config_get_database_notmuch_path (notmuch_config_t *config);\r
80 +\r
81 +void\r
82 +notmuch_config_set_database_notmuch_path (notmuch_config_t *config,\r
83 +                                         const char *database_notmuch_path);\r
84 +\r
85  notmuch_database_t *\r
86  notmuch_config_open_database (notmuch_config_t *config,\r
87                               notmuch_database_mode_t mode);\r
88 diff --git a/notmuch-config.c b/notmuch-config.c\r
89 index 58a28b1..ccae35d 100644\r
90 --- a/notmuch-config.c\r
91 +++ b/notmuch-config.c\r
92 @@ -58,6 +58,7 @@ struct _notmuch_config {\r
93      GKeyFile *key_file;\r
94  \r
95      char *database_path;\r
96 +    char *database_notmuch_path;\r
97      char *user_name;\r
98      char *user_primary_email;\r
99      char **user_other_email;\r
100 @@ -151,6 +152,8 @@ get_username_from_passwd_file (void *ctx)\r
101   *\r
102   *     database_path:          $HOME/mail\r
103   *\r
104 + *     database_notmuch_path:  database_path/.notmuch\r
105 + *\r
106   *     user_name:              From /etc/passwd\r
107   *\r
108   *     user_primary_mail:      $EMAIL variable if set, otherwise\r
109 @@ -195,6 +198,7 @@ notmuch_config_open (void *ctx,\r
110      config->key_file = g_key_file_new ();\r
111  \r
112      config->database_path = NULL;\r
113 +    config->database_notmuch_path = NULL;\r
114      config->user_name = NULL;\r
115      config->user_primary_email = NULL;\r
116      config->user_other_email = NULL;\r
117 @@ -351,6 +355,45 @@ notmuch_config_set_database_path (notmuch_config_t *config,\r
118  \r
119      talloc_free (config->database_path);\r
120      config->database_path = NULL;\r
121 +    /* In case this path is dynamically generated */\r
122 +    talloc_free (config->database_notmuch_path);\r
123 +    config->database_notmuch_path = NULL;\r
124 +}\r
125 +\r
126 +const char *\r
127 +notmuch_config_get_database_notmuch_path (notmuch_config_t *config)\r
128 +{\r
129 +    const char *path;\r
130 +    char *notmuch_path;\r
131 +\r
132 +    if (config->database_notmuch_path == NULL) {\r
133 +       notmuch_path = g_key_file_get_string (config->key_file,\r
134 +                                             "database", "notmuch_path", NULL);\r
135 +       if (notmuch_path) {\r
136 +           config->database_notmuch_path = talloc_strdup (config, notmuch_path);\r
137 +           free (notmuch_path);\r
138 +       } else {\r
139 +           path = notmuch_config_get_database_path (config);\r
140 +           if (path != NULL) {\r
141 +               notmuch_path = talloc_asprintf (config, "%s/%s",\r
142 +                                               path, ".notmuch");\r
143 +               config->database_notmuch_path = notmuch_path;\r
144 +           }\r
145 +       }\r
146 +    }\r
147 +\r
148 +    return config->database_notmuch_path;\r
149 +}\r
150 +\r
151 +void\r
152 +notmuch_config_set_database_notmuch_path (notmuch_config_t *config,\r
153 +                                         const char *database_notmuch_path)\r
154 +{\r
155 +    g_key_file_set_string (config->key_file,\r
156 +                          "database", "notmuch_path", database_notmuch_path);\r
157 +\r
158 +    talloc_free (config->database_notmuch_path);\r
159 +    config->database_notmuch_path = NULL;\r
160  }\r
161  \r
162  notmuch_database_t *\r
163 @@ -358,26 +401,13 @@ notmuch_config_open_database (notmuch_config_t *config,\r
164                               notmuch_database_mode_t mode)\r
165  {\r
166      const char *path = NULL;\r
167 -    char *db_path = NULL;\r
168 +    const char *notmuch_path = NULL;\r
169      notmuch_database_t *notmuch = NULL;\r
170  \r
171      path = notmuch_config_get_database_path (config);\r
172 -    if (path == NULL) {\r
173 -       fprintf (stderr, "Error: Cannot create a database for a NULL path.\n");\r
174 -       goto DONE;\r
175 -    }\r
176 -\r
177 -    if (asprintf (&db_path, "%s/%s", path, ".notmuch") == -1) {\r
178 -       db_path = NULL;\r
179 -       fprintf (stderr, "Out of memory\n");\r
180 -       goto DONE;\r
181 -    }\r
182 -\r
183 -    notmuch = notmuch_database_open (path, db_path, mode);\r
184 +    notmuch_path = notmuch_config_get_database_notmuch_path (config);\r
185  \r
186 -DONE:\r
187 -    if (db_path)\r
188 -       free(db_path);\r
189 +    notmuch = notmuch_database_open (path, notmuch_path, mode);\r
190  \r
191      return notmuch;\r
192  }\r
193 diff --git a/notmuch-new.c b/notmuch-new.c\r
194 index d24dab9..d36edd5 100644\r
195 --- a/notmuch-new.c\r
196 +++ b/notmuch-new.c\r
197 @@ -713,7 +713,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
198      int ret = 0;\r
199      struct stat st;\r
200      const char *db_path;\r
201 -    char *dot_notmuch_path;\r
202 +    const char *notmuch_path;\r
203      struct sigaction action;\r
204      _filename_node_t *f;\r
205      int renamed_files, removed_files;\r
206 @@ -737,10 +737,9 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
207         return 1;\r
208  \r
209      db_path = notmuch_config_get_database_path (config);\r
210 +    notmuch_path = notmuch_config_get_database_notmuch_path (config);\r
211  \r
212 -    dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");\r
213 -\r
214 -    if (stat (dot_notmuch_path, &st)) {\r
215 +    if (stat (notmuch_path, &st)) {\r
216         int count;\r
217  \r
218         count = 0;\r
219 @@ -749,11 +748,11 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
220             return 1;\r
221  \r
222         printf ("Found %d total files (that's not much mail).\n", count);\r
223 -       notmuch = notmuch_database_create (db_path, dot_notmuch_path);\r
224 +       notmuch = notmuch_database_create (db_path, notmuch_path);\r
225         add_files_state.total_files = count;\r
226      } else {\r
227         notmuch = notmuch_database_open (db_path,\r
228 -                                        dot_notmuch_path,\r
229 +                                        notmuch_path,\r
230                                          NOTMUCH_DATABASE_MODE_READ_WRITE);\r
231         if (notmuch == NULL)\r
232             return 1;\r
233 @@ -782,9 +781,6 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
234      action.sa_flags = SA_RESTART;\r
235      sigaction (SIGINT, &action, NULL);\r
236  \r
237 -    talloc_free (dot_notmuch_path);\r
238 -    dot_notmuch_path = NULL;\r
239 -\r
240      add_files_state.processed_files = 0;\r
241      add_files_state.added_messages = 0;\r
242      gettimeofday (&add_files_state.tv_start, NULL);\r
243 -- \r
244 1.7.0.18.g39b3\r
245 \r