1 Return-Path: <ethan.glasser.camp@gmail.com>
\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 1C210431FB6
\r
6 for <notmuch@notmuchmail.org>; Mon, 25 Jun 2012 13:54:08 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=1.061 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 FREEMAIL_FROM=0.001, RCVD_IN_BL_SPAMCOP_NET=1.246,
\r
14 RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_SORBS_WEB=0.614] autolearn=disabled
\r
15 Received: from olra.theworths.org ([127.0.0.1])
\r
16 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
17 with ESMTP id 1mh-z2GsTlVk for <notmuch@notmuchmail.org>;
\r
18 Mon, 25 Jun 2012 13:54:07 -0700 (PDT)
\r
19 Received: from mail-we0-f181.google.com (mail-we0-f181.google.com
\r
20 [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
21 (No client certificate requested)
\r
22 by olra.theworths.org (Postfix) with ESMTPS id 09637431FAF
\r
23 for <notmuch@notmuchmail.org>; Mon, 25 Jun 2012 13:54:06 -0700 (PDT)
\r
24 Received: by werj55 with SMTP id j55so3649559wer.26
\r
25 for <notmuch@notmuchmail.org>; Mon, 25 Jun 2012 13:54:05 -0700 (PDT)
\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
\r
27 h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;
\r
28 bh=nrU9nVmzJXJsXKqS8m11Z17v5gUa/3MWhEq27JiKUS0=;
\r
29 b=06M9rpHV51pq0hSDUnstkj43T96lpndJYsr7E4fkp9ggg47Cp1277Rs7O7Zu4gO0DC
\r
30 L6D7d1TdJztUdDfVcBItE86vII7fymd9GecWXTJ3JRBu87qq5ACbwnXBbGdrYkAA2FwX
\r
31 ef33s8OZ4w3CvknGX55pWvnQsgeewwGZzyr3ONT5sdV+qg69wgxEi575UFTOl8Y+1h9M
\r
32 WhfK3Z/jNHZx1dl4KWBRY8nPLKJr9ndIwvY8+EjOVUtI3HFK/DKPlqnylUrYPksaCU6c
\r
33 p3isfgN7zSTp9hCeQ90zLZRjfFN7TCWYmLuiOwZNMljTiWH0R7uPFaq1qVDiAR2s3/VW
\r
35 Received: by 10.180.24.39 with SMTP id r7mr27675594wif.9.1340657645740;
\r
36 Mon, 25 Jun 2012 13:54:05 -0700 (PDT)
\r
37 Received: from localhost ([195.24.209.21])
\r
38 by mx.google.com with ESMTPS id t8sm34175wiy.3.2012.06.25.13.54.00
\r
39 (version=TLSv1/SSLv3 cipher=OTHER);
\r
40 Mon, 25 Jun 2012 13:54:04 -0700 (PDT)
\r
41 From: Ethan Glasser-Camp <ethan.glasser.camp@gmail.com>
\r
42 To: notmuch@notmuchmail.org
\r
43 Subject: [RFC PATCH 11/14] notmuch-new: pull out useful bits of
\r
45 Date: Mon, 25 Jun 2012 16:51:54 -0400
\r
46 Message-Id: <1340657517-6539-7-git-send-email-ethan@betacantrips.com>
\r
47 X-Mailer: git-send-email 1.7.9.5
\r
48 In-Reply-To: <1340657517-6539-1-git-send-email-ethan@betacantrips.com>
\r
49 References: <1340657517-6539-1-git-send-email-ethan@betacantrips.com>
\r
50 X-Mailman-Approved-At: Tue, 26 Jun 2012 03:51:54 -0700
\r
51 X-BeenThere: notmuch@notmuchmail.org
\r
52 X-Mailman-Version: 2.1.13
\r
54 List-Id: "Use and development of the notmuch mail system."
\r
55 <notmuch.notmuchmail.org>
\r
56 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
57 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
58 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
59 List-Post: <mailto:notmuch@notmuchmail.org>
\r
60 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
61 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
62 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
63 X-List-Received-Date: Mon, 25 Jun 2012 20:54:08 -0000
\r
65 This is part of notmuch-new refactor phase 1: make add_files stuff
\r
66 safe for other backends. add_files_recursive is essentially a
\r
67 maildir-crawling function that periodically adds files to the database
\r
68 or adds filenames to remove_files or remove_directory lists. I don't
\r
69 see an easy way to adapt add_files_recursive for other backends who
\r
70 might not have concepts of directories with other directories inside
\r
71 of them, so instead just provide an add_files method for each backend.
\r
73 This patch pulls some bits out of add_files_recursive which will be
\r
74 useful for other backends: two reporting functions
\r
75 _report_before_adding_file and _report_added_file, as well as
\r
76 _add_message, which actually does the message adding.
\r
78 Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com>
\r
80 notmuch-new.c | 192 +++++++++++++++++++++++++++++++++++----------------------
\r
81 1 file changed, 119 insertions(+), 73 deletions(-)
\r
83 diff --git a/notmuch-new.c b/notmuch-new.c
\r
84 index 57b27bf..1bf4e25 100644
\r
87 @@ -249,6 +249,122 @@ add_files_uri (unused(notmuch_database_t *notmuch),
\r
88 return NOTMUCH_STATUS_SUCCESS;
\r
91 +/* Progress-reporting function.
\r
93 + * Can be used by any mailstore-crawling function that wants to alert
\r
94 + * users what message it's about to add. Subsequent errors will be due
\r
95 + * to this message ;)
\r
98 +_report_before_adding_file (add_files_state_t *state, const char *filename)
\r
100 + state->processed_files++;
\r
102 + if (state->verbose) {
\r
103 + if (state->output_is_a_tty)
\r
104 + printf("\r\033[K");
\r
106 + printf ("%i/%i: %s",
\r
107 + state->processed_files,
\r
108 + state->total_files,
\r
111 + putchar((state->output_is_a_tty) ? '\r' : '\n');
\r
116 +/* Progress-reporting function.
\r
118 + * Call this to respond to the signal handler for SIGALRM.
\r
121 +_report_added_file (add_files_state_t *state)
\r
123 + if (do_print_progress) {
\r
124 + do_print_progress = 0;
\r
125 + generic_print_progress ("Processed", "files", state->tv_start,
\r
126 + state->processed_files, state->total_files);
\r
131 +/* Atomically handles adding a message to the database.
\r
133 + * Should be used by any mailstore-crawling function that finds a new
\r
134 + * message to add.
\r
136 +static notmuch_status_t
\r
137 +_add_message (add_files_state_t *state, notmuch_database_t *notmuch,
\r
138 + const char *filename)
\r
140 + notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;
\r
141 + notmuch_message_t *message;
\r
142 + const char **tag;
\r
144 + status = notmuch_database_begin_atomic (notmuch);
\r
150 + status = notmuch_database_add_message (notmuch, filename, &message);
\r
152 + switch (status) {
\r
154 + case NOTMUCH_STATUS_SUCCESS:
\r
155 + state->added_messages++;
\r
156 + notmuch_message_freeze (message);
\r
157 + for (tag=state->new_tags; *tag != NULL; tag++)
\r
158 + notmuch_message_add_tag (message, *tag);
\r
159 + if (state->synchronize_flags == TRUE)
\r
160 + notmuch_message_maildir_flags_to_tags (message);
\r
161 + notmuch_message_thaw (message);
\r
163 + /* Non-fatal issues (go on to next file) */
\r
164 + case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
\r
165 + if (state->synchronize_flags == TRUE)
\r
166 + notmuch_message_maildir_flags_to_tags (message);
\r
168 + case NOTMUCH_STATUS_FILE_NOT_EMAIL:
\r
169 + fprintf (stderr, "Note: Ignoring non-mail file: %s\n",
\r
172 + /* Fatal issues. Don't process anymore. */
\r
173 + case NOTMUCH_STATUS_READ_ONLY_DATABASE:
\r
174 + case NOTMUCH_STATUS_XAPIAN_EXCEPTION:
\r
175 + case NOTMUCH_STATUS_OUT_OF_MEMORY:
\r
176 + fprintf (stderr, "Error: %s. Halting processing.\n",
\r
177 + notmuch_status_to_string (status));
\r
181 + case NOTMUCH_STATUS_FILE_ERROR:
\r
182 + case NOTMUCH_STATUS_NULL_POINTER:
\r
183 + case NOTMUCH_STATUS_TAG_TOO_LONG:
\r
184 + case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:
\r
185 + case NOTMUCH_STATUS_UNBALANCED_ATOMIC:
\r
186 + case NOTMUCH_STATUS_LAST_STATUS:
\r
187 + INTERNAL_ERROR ("add_message returned unexpected value: %d", status);
\r
192 + status = notmuch_database_end_atomic (notmuch);
\r
200 + notmuch_message_destroy (message);
\r
207 /* Examine 'path' recursively as follows:
\r
209 * o Ask the filesystem for the mtime of 'path' (fs_mtime)
\r
210 @@ -300,7 +416,6 @@ add_files (notmuch_database_t *notmuch,
\r
211 char *next = NULL, *path_uri = NULL;
\r
212 time_t fs_mtime, db_mtime;
\r
213 notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;
\r
214 - notmuch_message_t *message = NULL;
\r
215 struct dirent **fs_entries = NULL;
\r
216 int i, num_fs_entries = 0, entry_type;
\r
217 notmuch_directory_t *directory;
\r
218 @@ -309,7 +424,6 @@ add_files (notmuch_database_t *notmuch,
\r
221 notmuch_bool_t is_maildir;
\r
222 - const char **tag;
\r
224 if (stat (path, &st)) {
\r
225 fprintf (stderr, "Error reading directory %s: %s\n",
\r
226 @@ -488,83 +602,15 @@ add_files (notmuch_database_t *notmuch,
\r
227 * in the database, so add it. */
\r
228 next = talloc_asprintf (notmuch, "%s/%s", path_uri, entry->d_name);
\r
230 - state->processed_files++;
\r
232 - if (state->verbose) {
\r
233 - if (state->output_is_a_tty)
\r
234 - printf("\r\033[K");
\r
236 - printf ("%i/%i: %s",
\r
237 - state->processed_files,
\r
238 - state->total_files,
\r
241 - putchar((state->output_is_a_tty) ? '\r' : '\n');
\r
244 + _report_before_adding_file (state, next);
\r
246 - status = notmuch_database_begin_atomic (notmuch);
\r
247 + status = _add_message (state, notmuch, next);
\r
253 - status = notmuch_database_add_message (notmuch, next, &message);
\r
254 - switch (status) {
\r
256 - case NOTMUCH_STATUS_SUCCESS:
\r
257 - state->added_messages++;
\r
258 - notmuch_message_freeze (message);
\r
259 - for (tag=state->new_tags; *tag != NULL; tag++)
\r
260 - notmuch_message_add_tag (message, *tag);
\r
261 - if (state->synchronize_flags == TRUE)
\r
262 - notmuch_message_maildir_flags_to_tags (message);
\r
263 - notmuch_message_thaw (message);
\r
265 - /* Non-fatal issues (go on to next file) */
\r
266 - case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
\r
267 - if (state->synchronize_flags == TRUE)
\r
268 - notmuch_message_maildir_flags_to_tags (message);
\r
270 - case NOTMUCH_STATUS_FILE_NOT_EMAIL:
\r
271 - fprintf (stderr, "Note: Ignoring non-mail file: %s\n",
\r
274 - /* Fatal issues. Don't process anymore. */
\r
275 - case NOTMUCH_STATUS_READ_ONLY_DATABASE:
\r
276 - case NOTMUCH_STATUS_XAPIAN_EXCEPTION:
\r
277 - case NOTMUCH_STATUS_OUT_OF_MEMORY:
\r
278 - fprintf (stderr, "Error: %s. Halting processing.\n",
\r
279 - notmuch_status_to_string (status));
\r
283 - case NOTMUCH_STATUS_FILE_ERROR:
\r
284 - case NOTMUCH_STATUS_NULL_POINTER:
\r
285 - case NOTMUCH_STATUS_TAG_TOO_LONG:
\r
286 - case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:
\r
287 - case NOTMUCH_STATUS_UNBALANCED_ATOMIC:
\r
288 - case NOTMUCH_STATUS_LAST_STATUS:
\r
289 - INTERNAL_ERROR ("add_message returned unexpected value: %d", status);
\r
293 - status = notmuch_database_end_atomic (notmuch);
\r
300 - notmuch_message_destroy (message);
\r
304 - if (do_print_progress) {
\r
305 - do_print_progress = 0;
\r
306 - generic_print_progress ("Processed", "files", state->tv_start,
\r
307 - state->processed_files, state->total_files);
\r
309 + _report_added_file (state);
\r
311 talloc_free (next);
\r