1 Return-Path: <sojkam1@fel.cvut.cz>
\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 154F7404964
\r
6 for <notmuch@notmuchmail.org>; Thu, 18 Mar 2010 08:41:03 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.272 tagged_above=-999 required=5 tests=[AWL=0.327,
\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 QOzVBAr5IYSK for <notmuch@notmuchmail.org>;
\r
16 Thu, 18 Mar 2010 08:40:57 -0700 (PDT)
\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])
\r
18 by olra.theworths.org (Postfix) with ESMTP id E86A040495F
\r
19 for <notmuch@notmuchmail.org>; Thu, 18 Mar 2010 08:40:54 -0700 (PDT)
\r
20 Received: from localhost (unknown [192.168.200.4])
\r
21 by max.feld.cvut.cz (Postfix) with ESMTP id 542C419F3401;
\r
22 Thu, 18 Mar 2010 16:40:54 +0100 (CET)
\r
23 X-Virus-Scanned: IMAP AMAVIS
\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])
\r
25 by localhost (styx.feld.cvut.cz [192.168.200.4]) (amavisd-new,
\r
27 with ESMTP id jEwR7Ce5rT+J; Thu, 18 Mar 2010 16:40:51 +0100 (CET)
\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])
\r
29 by max.feld.cvut.cz (Postfix) with ESMTP id 6262719F3406;
\r
30 Thu, 18 Mar 2010 16:40:51 +0100 (CET)
\r
31 Received: from steelpick.localdomain (k335-30.felk.cvut.cz [147.32.86.30])
\r
32 (Authenticated sender: sojkam1)
\r
33 by imap.feld.cvut.cz (Postfix) with ESMTPSA id 37B5DFA005;
\r
34 Thu, 18 Mar 2010 16:40:51 +0100 (CET)
\r
35 Received: from wsh by steelpick.localdomain with local (Exim 4.71)
\r
36 (envelope-from <sojkam1@fel.cvut.cz>)
\r
37 id 1NsHq6-0005Hj-Uu; Thu, 18 Mar 2010 16:40:51 +0100
\r
38 From: Michal Sojka <sojkam1@fel.cvut.cz>
\r
39 To: notmuch@notmuchmail.org
\r
40 Date: Thu, 18 Mar 2010 16:39:38 +0100
\r
41 Message-Id: <1268926780-20045-3-git-send-email-sojkam1@fel.cvut.cz>
\r
42 X-Mailer: git-send-email 1.7.0
\r
43 In-Reply-To: <1268926780-20045-1-git-send-email-sojkam1@fel.cvut.cz>
\r
44 References: <1268926780-20045-1-git-send-email-sojkam1@fel.cvut.cz>
\r
45 Subject: [notmuch] [PATCH 2/4] Convert mailstore abstraction
\r
46 X-BeenThere: notmuch@notmuchmail.org
\r
47 X-Mailman-Version: 2.1.13
\r
49 List-Id: "Use and development of the notmuch mail system."
\r
50 <notmuch.notmuchmail.org>
\r
51 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
52 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
53 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
54 List-Post: <mailto:notmuch@notmuchmail.org>
\r
55 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
56 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
57 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
58 X-List-Received-Date: Thu, 18 Mar 2010 15:41:03 -0000
\r
60 The code for detection of new files in the mailstore and their
\r
61 addition to the database is moved from notmuch-new.c to
\r
62 lib/mailstore-files.c, where it is called by the abstract mailstore
\r
65 The code was changed to allow the progress reporting function to be
\r
66 implemented outside of notmuch library.
\r
68 Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
\r
70 lib/mailstore-files.c | 590 +++++++++++++++++++++++++++++++++++++++++++++++
\r
71 notmuch-new.c | 611 ++-----------------------------------------------
\r
72 2 files changed, 615 insertions(+), 586 deletions(-)
\r
74 diff --git a/lib/mailstore-files.c b/lib/mailstore-files.c
\r
75 index 92d7f5d..ace2664 100644
\r
76 --- a/lib/mailstore-files.c
\r
77 +++ b/lib/mailstore-files.c
\r
79 * Michal Sojka <sojkam1@fel.cvut.cz>
\r
82 +#define _GNU_SOURCE /* For asprintf() */
\r
83 #include "notmuch.h"
\r
84 #include "mailstore-private.h"
\r
85 +#include <dirent.h>
\r
87 +typedef struct _filename_node {
\r
89 + struct _filename_node *next;
\r
90 +} _filename_node_t;
\r
92 +typedef struct _filename_list {
\r
93 + _filename_node_t *head;
\r
94 + _filename_node_t **tail;
\r
95 +} _filename_list_t;
\r
97 +typedef struct _indexing_context_priv {
\r
98 + _filename_list_t *removed_files;
\r
99 + _filename_list_t *removed_directories;
\r
100 +} _indexing_context_priv_t;
\r
102 +static _filename_list_t *
\r
103 +_filename_list_create (const void *ctx)
\r
105 + _filename_list_t *list;
\r
107 + list = talloc (ctx, _filename_list_t);
\r
108 + if (list == NULL)
\r
111 + list->head = NULL;
\r
112 + list->tail = &list->head;
\r
118 +_filename_list_add (_filename_list_t *list,
\r
119 + const char *filename)
\r
121 + _filename_node_t *node = talloc (list, _filename_node_t);
\r
123 + node->filename = talloc_strdup (list, filename);
\r
124 + node->next = NULL;
\r
126 + *(list->tail) = node;
\r
127 + list->tail = &node->next;
\r
131 +tag_inbox_and_unread (notmuch_message_t *message)
\r
133 + notmuch_message_add_tag (message, "inbox");
\r
134 + notmuch_message_add_tag (message, "unread");
\r
138 +dirent_sort_inode (const struct dirent **a, const struct dirent **b)
\r
140 + return ((*a)->d_ino < (*b)->d_ino) ? -1 : 1;
\r
144 +dirent_sort_strcmp_name (const struct dirent **a, const struct dirent **b)
\r
146 + return strcmp ((*a)->d_name, (*b)->d_name);
\r
149 +/* Test if the directory looks like a Maildir directory.
\r
151 + * Search through the array of directory entries to see if we can find all
\r
152 + * three subdirectories typical for Maildir, that is "new", "cur", and "tmp".
\r
154 + * Return 1 if the directory looks like a Maildir and 0 otherwise.
\r
157 +_entries_resemble_maildir (struct dirent **entries, int count)
\r
159 + int i, found = 0;
\r
161 + for (i = 0; i < count; i++) {
\r
162 + if (entries[i]->d_type != DT_DIR && entries[i]->d_type != DT_UNKNOWN)
\r
165 + if (strcmp(entries[i]->d_name, "new") == 0 ||
\r
166 + strcmp(entries[i]->d_name, "cur") == 0 ||
\r
167 + strcmp(entries[i]->d_name, "tmp") == 0)
\r
179 +/* Examine 'path' recursively as follows:
\r
181 + * o Ask the filesystem for the mtime of 'path' (fs_mtime)
\r
182 + * o Ask the database for its timestamp of 'path' (db_mtime)
\r
184 + * o Ask the filesystem for files and directories within 'path'
\r
185 + * (via scandir and stored in fs_entries)
\r
186 + * o Ask the database for files and directories within 'path'
\r
187 + * (db_files and db_subdirs)
\r
189 + * o Pass 1: For each directory in fs_entries, recursively call into
\r
190 + * this same function.
\r
192 + * o Pass 2: If 'fs_mtime' > 'db_mtime', then walk fs_entries
\r
193 + * simultaneously with db_files and db_subdirs. Look for one of
\r
194 + * three interesting cases:
\r
196 + * 1. Regular file in fs_entries and not in db_files
\r
197 + * This is a new file to add_message into the database.
\r
199 + * 2. Filename in db_files not in fs_entries.
\r
200 + * This is a file that has been removed from the mail store.
\r
202 + * 3. Directory in db_subdirs not in fs_entries
\r
203 + * This is a directory that has been removed from the mail store.
\r
205 + * Note that the addition of a directory is not interesting here,
\r
206 + * since that will have been taken care of in pass 1. Also, we
\r
207 + * don't immediately act on file/directory removal since we must
\r
208 + * ensure that in the case of a rename that the new filename is
\r
209 + * added before the old filename is removed, (so that no
\r
210 + * information is lost from the database).
\r
212 + * o Tell the database to update its time of 'path' to 'fs_mtime'
\r
214 +static notmuch_status_t
\r
215 +add_files_recursive (notmuch_mailstore_t *mailstore,
\r
216 + const char *path,
\r
217 + notmuch_indexing_context_t *state)
\r
220 + struct dirent *entry = NULL;
\r
221 + char *next = NULL;
\r
222 + time_t fs_mtime, db_mtime;
\r
223 + notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;
\r
224 + notmuch_message_t *message = NULL;
\r
225 + struct dirent **fs_entries = NULL;
\r
226 + int i, num_fs_entries;
\r
227 + notmuch_directory_t *directory;
\r
228 + notmuch_filenames_t *db_files = NULL;
\r
229 + notmuch_filenames_t *db_subdirs = NULL;
\r
231 + notmuch_bool_t is_maildir, new_directory;
\r
232 + _indexing_context_priv_t *priv = state->priv;
\r
233 + notmuch_database_t *notmuch = mailstore->notmuch;
\r
235 + if (stat (path, &st)) {
\r
236 + fprintf (stderr, "Error reading directory %s: %s\n",
\r
237 + path, strerror (errno));
\r
238 + return NOTMUCH_STATUS_FILE_ERROR;
\r
241 + /* This is not an error since we may have recursed based on a
\r
242 + * symlink to a regular file, not a directory, and we don't know
\r
243 + * that until this stat. */
\r
244 + if (! S_ISDIR (st.st_mode))
\r
245 + return NOTMUCH_STATUS_SUCCESS;
\r
247 + fs_mtime = st.st_mtime;
\r
249 + directory = notmuch_database_get_directory (notmuch, path);
\r
250 + db_mtime = notmuch_directory_get_mtime (directory);
\r
252 + if (db_mtime == 0) {
\r
253 + new_directory = TRUE;
\r
255 + db_subdirs = NULL;
\r
257 + new_directory = FALSE;
\r
258 + db_files = notmuch_directory_get_child_files (directory);
\r
259 + db_subdirs = notmuch_directory_get_child_directories (directory);
\r
262 + /* If the database knows about this directory, then we sort based
\r
263 + * on strcmp to match the database sorting. Otherwise, we can do
\r
264 + * inode-based sorting for faster filesystem operation. */
\r
265 + num_fs_entries = scandir (path, &fs_entries, 0,
\r
267 + dirent_sort_inode : dirent_sort_strcmp_name);
\r
269 + if (num_fs_entries == -1) {
\r
270 + fprintf (stderr, "Error opening directory %s: %s\n",
\r
271 + path, strerror (errno));
\r
272 + ret = NOTMUCH_STATUS_FILE_ERROR;
\r
276 + /* Pass 1: Recurse into all sub-directories. */
\r
277 + is_maildir = _entries_resemble_maildir (fs_entries, num_fs_entries);
\r
279 + for (i = 0; i < num_fs_entries; i++) {
\r
280 + if (state->interrupted)
\r
283 + entry = fs_entries[i];
\r
285 + /* We only want to descend into directories.
\r
286 + * But symlinks can be to directories too, of course.
\r
288 + * And if the filesystem doesn't tell us the file type in the
\r
289 + * scandir results, then it might be a directory (and if not,
\r
290 + * then we'll stat and return immediately in the next level of
\r
292 + if (entry->d_type != DT_DIR &&
\r
293 + entry->d_type != DT_LNK &&
\r
294 + entry->d_type != DT_UNKNOWN)
\r
299 + /* Ignore special directories to avoid infinite recursion.
\r
300 + * Also ignore the .notmuch directory and any "tmp" directory
\r
301 + * that appears within a maildir.
\r
303 + /* XXX: Eventually we'll want more sophistication to let the
\r
304 + * user specify files to be ignored. */
\r
305 + if (strcmp (entry->d_name, ".") == 0 ||
\r
306 + strcmp (entry->d_name, "..") == 0 ||
\r
307 + (is_maildir && strcmp (entry->d_name, "tmp") == 0) ||
\r
308 + strcmp (entry->d_name, ".notmuch") ==0)
\r
313 + next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
\r
314 + status = add_files_recursive (mailstore, next, state);
\r
315 + if (status && ret == NOTMUCH_STATUS_SUCCESS)
\r
317 + talloc_free (next);
\r
321 + /* If this directory hasn't been modified since the last
\r
322 + * "notmuch new", then we can skip the second pass entirely. */
\r
323 + if (fs_mtime <= db_mtime)
\r
326 + /* Pass 2: Scan for new files, removed files, and removed directories. */
\r
327 + for (i = 0; i < num_fs_entries; i++)
\r
329 + if (state->interrupted)
\r
332 + entry = fs_entries[i];
\r
334 + /* Check if we've walked past any names in db_files or
\r
335 + * db_subdirs. If so, these have been deleted. */
\r
336 + while (notmuch_filenames_valid (db_files) &&
\r
337 + strcmp (notmuch_filenames_get (db_files), entry->d_name) < 0)
\r
339 + char *absolute = talloc_asprintf (priv->removed_files,
\r
341 + notmuch_filenames_get (db_files));
\r
343 + _filename_list_add (priv->removed_files, absolute);
\r
345 + notmuch_filenames_move_to_next (db_files);
\r
348 + while (notmuch_filenames_valid (db_subdirs) &&
\r
349 + strcmp (notmuch_filenames_get (db_subdirs), entry->d_name) <= 0)
\r
351 + const char *filename = notmuch_filenames_get (db_subdirs);
\r
353 + if (strcmp (filename, entry->d_name) < 0)
\r
355 + char *absolute = talloc_asprintf (priv->removed_directories,
\r
356 + "%s/%s", path, filename);
\r
358 + _filename_list_add (priv->removed_directories, absolute);
\r
361 + notmuch_filenames_move_to_next (db_subdirs);
\r
364 + /* If we're looking at a symlink, we only want to add it if it
\r
365 + * links to a regular file, (and not to a directory, say).
\r
367 + * Similarly, if the file is of unknown type (due to filesytem
\r
368 + * limitations), then we also need to look closer.
\r
370 + * In either case, a stat does the trick.
\r
372 + if (entry->d_type == DT_LNK || entry->d_type == DT_UNKNOWN) {
\r
375 + next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
\r
376 + err = stat (next, &st);
\r
377 + talloc_free (next);
\r
380 + /* Don't emit an error for a link pointing nowhere, since
\r
381 + * the directory-traversal pass will have already done
\r
386 + if (! S_ISREG (st.st_mode))
\r
388 + } else if (entry->d_type != DT_REG) {
\r
392 + /* Don't add a file that we've added before. */
\r
393 + if (notmuch_filenames_valid (db_files) &&
\r
394 + strcmp (notmuch_filenames_get (db_files), entry->d_name) == 0)
\r
396 + notmuch_filenames_move_to_next (db_files);
\r
400 + /* We're now looking at a regular file that doesn't yet exist
\r
401 + * in the database, so add it. */
\r
402 + next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
\r
404 + state->processed_files++;
\r
406 + if (state->verbose) {
\r
407 + if (state->output_is_a_tty)
\r
408 + printf("\r\033[K");
\r
410 + printf ("%i/%i: %s",
\r
411 + state->processed_files,
\r
412 + state->total_files,
\r
415 + putchar((state->output_is_a_tty) ? '\r' : '\n');
\r
419 + status = notmuch_database_add_message (notmuch, next, &message);
\r
420 + switch (status) {
\r
422 + case NOTMUCH_STATUS_SUCCESS:
\r
423 + state->added_messages++;
\r
424 + tag_inbox_and_unread (message);
\r
426 + /* Non-fatal issues (go on to next file) */
\r
427 + case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
\r
428 + /* Stay silent on this one. */
\r
430 + case NOTMUCH_STATUS_FILE_NOT_EMAIL:
\r
431 + fprintf (stderr, "Note: Ignoring non-mail file: %s\n",
\r
434 + /* Fatal issues. Don't process anymore. */
\r
435 + case NOTMUCH_STATUS_READ_ONLY_DATABASE:
\r
436 + case NOTMUCH_STATUS_XAPIAN_EXCEPTION:
\r
437 + case NOTMUCH_STATUS_OUT_OF_MEMORY:
\r
438 + fprintf (stderr, "Error: %s. Halting processing.\n",
\r
439 + notmuch_status_to_string (status));
\r
443 + case NOTMUCH_STATUS_FILE_ERROR:
\r
444 + case NOTMUCH_STATUS_NULL_POINTER:
\r
445 + case NOTMUCH_STATUS_TAG_TOO_LONG:
\r
446 + case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:
\r
447 + case NOTMUCH_STATUS_LAST_STATUS:
\r
448 + INTERNAL_ERROR ("add_message returned unexpected value: %d", status);
\r
453 + notmuch_message_destroy (message);
\r
457 + if (state->print_progress &&
\r
458 + state->print_progress_cb) {
\r
459 + state->print_progress = 0;
\r
460 + state->print_progress_cb (state);
\r
463 + talloc_free (next);
\r
467 + /* FIXME: Handle interrupted - there might be data loss */
\r
469 + /* Now that we've walked the whole filesystem list, anything left
\r
470 + * over in the database lists has been deleted. */
\r
471 + while (notmuch_filenames_valid (db_files))
\r
473 + char *absolute = talloc_asprintf (priv->removed_files,
\r
475 + notmuch_filenames_get (db_files));
\r
477 + _filename_list_add (priv->removed_files, absolute);
\r
479 + notmuch_filenames_move_to_next (db_files);
\r
482 + while (notmuch_filenames_valid (db_subdirs))
\r
484 + char *absolute = talloc_asprintf (priv->removed_directories,
\r
486 + notmuch_filenames_get (db_subdirs));
\r
488 + _filename_list_add (priv->removed_directories, absolute);
\r
490 + notmuch_filenames_move_to_next (db_subdirs);
\r
493 + if (! state->interrupted) {
\r
494 + status = notmuch_directory_set_mtime (directory, fs_mtime);
\r
495 + if (status && ret == NOTMUCH_STATUS_SUCCESS)
\r
501 + talloc_free (next);
\r
507 + free (fs_entries);
\r
509 + notmuch_filenames_destroy (db_subdirs);
\r
511 + notmuch_filenames_destroy (db_files);
\r
513 + notmuch_directory_destroy (directory);
\r
518 +/* XXX: This should be merged with the add_files function since it
\r
519 + * shares a lot of logic with it. */
\r
520 +/* Recursively count all regular files in path and all sub-directories
\r
521 + * of path. The result is added to *count (which should be
\r
522 + * initialized to zero by the top-level caller before calling
\r
523 + * count_files). */
\r
525 +count_files (notmuch_mailstore_t *mailstore,
\r
526 + const char *path, int *count,
\r
527 + volatile sig_atomic_t *interrupted)
\r
529 + struct dirent *entry = NULL;
\r
532 + struct dirent **fs_entries = NULL;
\r
533 + int num_fs_entries = scandir (path, &fs_entries, 0, dirent_sort_inode);
\r
537 + if (num_fs_entries == -1) {
\r
538 + fprintf (stderr, "Warning: failed to open directory %s: %s\n",
\r
539 + path, strerror (errno));
\r
543 + while (!*interrupted) {
\r
544 + if (i == num_fs_entries)
\r
547 + entry = fs_entries[i++];
\r
549 + /* Ignore special directories to avoid infinite recursion.
\r
550 + * Also ignore the .notmuch directory.
\r
552 + /* XXX: Eventually we'll want more sophistication to let the
\r
553 + * user specify files to be ignored. */
\r
554 + if (strcmp (entry->d_name, ".") == 0 ||
\r
555 + strcmp (entry->d_name, "..") == 0 ||
\r
556 + strcmp (entry->d_name, ".notmuch") == 0)
\r
561 + if (asprintf (&next, "%s/%s", path, entry->d_name) == -1) {
\r
563 + fprintf (stderr, "Error descending from %s to %s: Out of memory\n",
\r
564 + path, entry->d_name);
\r
568 + stat (next, &st);
\r
570 + if (S_ISREG (st.st_mode)) {
\r
571 + *count = *count + 1;
\r
572 + if (*count % 1000 == 0) {
\r
573 + printf ("Found %d files so far.\r", *count);
\r
576 + } else if (S_ISDIR (st.st_mode)) {
\r
577 + count_files (mailstore, next, count, interrupted);
\r
587 + free (fs_entries);
\r
590 +/* Recursively remove all filenames from the database referring to
\r
591 + * 'path' (or to any of its children). */
\r
593 +_remove_directory (void *ctx,
\r
594 + notmuch_database_t *notmuch,
\r
595 + const char *path,
\r
596 + int *renamed_files,
\r
597 + int *removed_files)
\r
599 + notmuch_directory_t *directory;
\r
600 + notmuch_filenames_t *files, *subdirs;
\r
601 + notmuch_status_t status;
\r
604 + directory = notmuch_database_get_directory (notmuch, path);
\r
606 + for (files = notmuch_directory_get_child_files (directory);
\r
607 + notmuch_filenames_valid (files);
\r
608 + notmuch_filenames_move_to_next (files))
\r
610 + absolute = talloc_asprintf (ctx, "%s/%s", path,
\r
611 + notmuch_filenames_get (files));
\r
612 + status = notmuch_database_remove_message (notmuch, absolute);
\r
613 + if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
\r
614 + *renamed_files = *renamed_files + 1;
\r
616 + *removed_files = *removed_files + 1;
\r
617 + talloc_free (absolute);
\r
620 + for (subdirs = notmuch_directory_get_child_directories (directory);
\r
621 + notmuch_filenames_valid (subdirs);
\r
622 + notmuch_filenames_move_to_next (subdirs))
\r
624 + absolute = talloc_asprintf (ctx, "%s/%s", path,
\r
625 + notmuch_filenames_get (subdirs));
\r
626 + _remove_directory (ctx, notmuch, absolute, renamed_files, removed_files);
\r
627 + talloc_free (absolute);
\r
630 + notmuch_directory_destroy (directory);
\r
633 +static notmuch_private_status_t
\r
634 +index_new(notmuch_mailstore_t *mailstore, const char* path,
\r
635 + notmuch_indexing_context_t *indexing_ctx)
\r
637 + _indexing_context_priv_t *priv;
\r
638 + _filename_node_t *f;
\r
639 + notmuch_status_t status, ret;
\r
640 + notmuch_database_t *notmuch = mailstore->notmuch;
\r
642 + priv = talloc(NULL, _indexing_context_priv_t);
\r
643 + indexing_ctx->priv = priv;
\r
644 + if (priv == NULL)
\r
645 + return NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
647 + priv->removed_files = _filename_list_create (priv);
\r
648 + priv->removed_directories = _filename_list_create (priv);
\r
650 + ret = add_files_recursive(mailstore, path, indexing_ctx);
\r
652 + indexing_ctx->removed_files = 0;
\r
653 + indexing_ctx->renamed_files = 0;
\r
654 + for (f = priv->removed_files->head; f; f = f->next) {
\r
655 + status = notmuch_database_remove_message (notmuch, f->filename);
\r
656 + if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
\r
657 + indexing_ctx->renamed_files++;
\r
659 + indexing_ctx->removed_files++;
\r
662 + for (f = priv->removed_directories->head; f; f = f->next) {
\r
663 + _remove_directory (priv, notmuch, f->filename,
\r
664 + &indexing_ctx->renamed_files,
\r
665 + &indexing_ctx->removed_files);
\r
668 + talloc_free(priv);
\r
674 open_file(notmuch_mailstore_t *mailstore, const char *filename)
\r
675 @@ -39,5 +626,8 @@ open_file(notmuch_mailstore_t *mailstore, const char *filename)
\r
676 /* Original notmuch mail store */
\r
677 struct _notmuch_mailstore mailstore_files = {
\r
679 + .count_files = count_files,
\r
680 + .index_new = index_new,
\r
681 + .sync_tags = NULL,
\r
682 .open_file = open_file,
\r
684 diff --git a/notmuch-new.c b/notmuch-new.c
\r
685 index 2d0ba6c..ede0859 100644
\r
686 --- a/notmuch-new.c
\r
687 +++ b/notmuch-new.c
\r
688 @@ -22,35 +22,12 @@
\r
690 #include <unistd.h>
\r
692 -typedef struct _filename_node {
\r
694 - struct _filename_node *next;
\r
695 -} _filename_node_t;
\r
697 -typedef struct _filename_list {
\r
698 - _filename_node_t *head;
\r
699 - _filename_node_t **tail;
\r
700 -} _filename_list_t;
\r
703 - int output_is_a_tty;
\r
707 - int processed_files;
\r
708 - int added_messages;
\r
709 - struct timeval tv_start;
\r
711 - _filename_list_t *removed_files;
\r
712 - _filename_list_t *removed_directories;
\r
713 -} add_files_state_t;
\r
715 -static volatile sig_atomic_t do_add_files_print_progress = 0;
\r
716 +notmuch_indexing_context_t *indexing_ctx;
\r
719 handle_sigalrm (unused (int signal))
\r
721 - do_add_files_print_progress = 1;
\r
722 + indexing_ctx->print_progress = 1;
\r
725 static volatile sig_atomic_t interrupted;
\r
726 @@ -62,46 +39,11 @@ handle_sigint (unused (int sig))
\r
727 static char msg[] = "Stopping... \n";
\r
729 ignored = write(2, msg, sizeof(msg)-1);
\r
733 -static _filename_list_t *
\r
734 -_filename_list_create (const void *ctx)
\r
736 - _filename_list_t *list;
\r
738 - list = talloc (ctx, _filename_list_t);
\r
739 - if (list == NULL)
\r
742 - list->head = NULL;
\r
743 - list->tail = &list->head;
\r
749 -_filename_list_add (_filename_list_t *list,
\r
750 - const char *filename)
\r
752 - _filename_node_t *node = talloc (list, _filename_node_t);
\r
754 - node->filename = talloc_strdup (list, filename);
\r
755 - node->next = NULL;
\r
757 - *(list->tail) = node;
\r
758 - list->tail = &node->next;
\r
759 + indexing_ctx->interrupted = 1;
\r
763 -tag_inbox_and_unread (notmuch_message_t *message)
\r
765 - notmuch_message_add_tag (message, "inbox");
\r
766 - notmuch_message_add_tag (message, "unread");
\r
770 -add_files_print_progress (add_files_state_t *state)
\r
771 +add_files_print_progress (notmuch_indexing_context_t *state)
\r
773 struct timeval tv_now;
\r
774 double elapsed_overall, rate_overall;
\r
775 @@ -128,388 +70,13 @@ add_files_print_progress (add_files_state_t *state)
\r
780 -dirent_sort_inode (const struct dirent **a, const struct dirent **b)
\r
782 - return ((*a)->d_ino < (*b)->d_ino) ? -1 : 1;
\r
786 -dirent_sort_strcmp_name (const struct dirent **a, const struct dirent **b)
\r
788 - return strcmp ((*a)->d_name, (*b)->d_name);
\r
791 -/* Test if the directory looks like a Maildir directory.
\r
793 - * Search through the array of directory entries to see if we can find all
\r
794 - * three subdirectories typical for Maildir, that is "new", "cur", and "tmp".
\r
796 - * Return 1 if the directory looks like a Maildir and 0 otherwise.
\r
799 -_entries_resemble_maildir (struct dirent **entries, int count)
\r
801 - int i, found = 0;
\r
803 - for (i = 0; i < count; i++) {
\r
804 - if (entries[i]->d_type != DT_DIR && entries[i]->d_type != DT_UNKNOWN)
\r
807 - if (strcmp(entries[i]->d_name, "new") == 0 ||
\r
808 - strcmp(entries[i]->d_name, "cur") == 0 ||
\r
809 - strcmp(entries[i]->d_name, "tmp") == 0)
\r
820 -/* Examine 'path' recursively as follows:
\r
822 - * o Ask the filesystem for the mtime of 'path' (fs_mtime)
\r
823 - * o Ask the database for its timestamp of 'path' (db_mtime)
\r
825 - * o Ask the filesystem for files and directories within 'path'
\r
826 - * (via scandir and stored in fs_entries)
\r
827 - * o Ask the database for files and directories within 'path'
\r
828 - * (db_files and db_subdirs)
\r
830 - * o Pass 1: For each directory in fs_entries, recursively call into
\r
831 - * this same function.
\r
833 - * o Pass 2: If 'fs_mtime' > 'db_mtime', then walk fs_entries
\r
834 - * simultaneously with db_files and db_subdirs. Look for one of
\r
835 - * three interesting cases:
\r
837 - * 1. Regular file in fs_entries and not in db_files
\r
838 - * This is a new file to add_message into the database.
\r
840 - * 2. Filename in db_files not in fs_entries.
\r
841 - * This is a file that has been removed from the mail store.
\r
843 - * 3. Directory in db_subdirs not in fs_entries
\r
844 - * This is a directory that has been removed from the mail store.
\r
846 - * Note that the addition of a directory is not interesting here,
\r
847 - * since that will have been taken care of in pass 1. Also, we
\r
848 - * don't immediately act on file/directory removal since we must
\r
849 - * ensure that in the case of a rename that the new filename is
\r
850 - * added before the old filename is removed, (so that no
\r
851 - * information is lost from the database).
\r
853 - * o Tell the database to update its time of 'path' to 'fs_mtime'
\r
855 -static notmuch_status_t
\r
856 -add_files_recursive (notmuch_database_t *notmuch,
\r
857 - const char *path,
\r
858 - add_files_state_t *state)
\r
861 - struct dirent *entry = NULL;
\r
862 - char *next = NULL;
\r
863 - time_t fs_mtime, db_mtime;
\r
864 - notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;
\r
865 - notmuch_message_t *message = NULL;
\r
866 - struct dirent **fs_entries = NULL;
\r
867 - int i, num_fs_entries;
\r
868 - notmuch_directory_t *directory;
\r
869 - notmuch_filenames_t *db_files = NULL;
\r
870 - notmuch_filenames_t *db_subdirs = NULL;
\r
872 - notmuch_bool_t is_maildir, new_directory;
\r
874 - if (stat (path, &st)) {
\r
875 - fprintf (stderr, "Error reading directory %s: %s\n",
\r
876 - path, strerror (errno));
\r
877 - return NOTMUCH_STATUS_FILE_ERROR;
\r
880 - /* This is not an error since we may have recursed based on a
\r
881 - * symlink to a regular file, not a directory, and we don't know
\r
882 - * that until this stat. */
\r
883 - if (! S_ISDIR (st.st_mode))
\r
884 - return NOTMUCH_STATUS_SUCCESS;
\r
886 - fs_mtime = st.st_mtime;
\r
888 - directory = notmuch_database_get_directory (notmuch, path);
\r
889 - db_mtime = notmuch_directory_get_mtime (directory);
\r
891 - if (db_mtime == 0) {
\r
892 - new_directory = TRUE;
\r
894 - db_subdirs = NULL;
\r
896 - new_directory = FALSE;
\r
897 - db_files = notmuch_directory_get_child_files (directory);
\r
898 - db_subdirs = notmuch_directory_get_child_directories (directory);
\r
901 - /* If the database knows about this directory, then we sort based
\r
902 - * on strcmp to match the database sorting. Otherwise, we can do
\r
903 - * inode-based sorting for faster filesystem operation. */
\r
904 - num_fs_entries = scandir (path, &fs_entries, 0,
\r
906 - dirent_sort_inode : dirent_sort_strcmp_name);
\r
908 - if (num_fs_entries == -1) {
\r
909 - fprintf (stderr, "Error opening directory %s: %s\n",
\r
910 - path, strerror (errno));
\r
911 - ret = NOTMUCH_STATUS_FILE_ERROR;
\r
915 - /* Pass 1: Recurse into all sub-directories. */
\r
916 - is_maildir = _entries_resemble_maildir (fs_entries, num_fs_entries);
\r
918 - for (i = 0; i < num_fs_entries; i++) {
\r
922 - entry = fs_entries[i];
\r
924 - /* We only want to descend into directories.
\r
925 - * But symlinks can be to directories too, of course.
\r
927 - * And if the filesystem doesn't tell us the file type in the
\r
928 - * scandir results, then it might be a directory (and if not,
\r
929 - * then we'll stat and return immediately in the next level of
\r
931 - if (entry->d_type != DT_DIR &&
\r
932 - entry->d_type != DT_LNK &&
\r
933 - entry->d_type != DT_UNKNOWN)
\r
938 - /* Ignore special directories to avoid infinite recursion.
\r
939 - * Also ignore the .notmuch directory and any "tmp" directory
\r
940 - * that appears within a maildir.
\r
942 - /* XXX: Eventually we'll want more sophistication to let the
\r
943 - * user specify files to be ignored. */
\r
944 - if (strcmp (entry->d_name, ".") == 0 ||
\r
945 - strcmp (entry->d_name, "..") == 0 ||
\r
946 - (is_maildir && strcmp (entry->d_name, "tmp") == 0) ||
\r
947 - strcmp (entry->d_name, ".notmuch") ==0)
\r
952 - next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
\r
953 - status = add_files_recursive (notmuch, next, state);
\r
954 - if (status && ret == NOTMUCH_STATUS_SUCCESS)
\r
956 - talloc_free (next);
\r
960 - /* If this directory hasn't been modified since the last
\r
961 - * "notmuch new", then we can skip the second pass entirely. */
\r
962 - if (fs_mtime <= db_mtime)
\r
965 - /* Pass 2: Scan for new files, removed files, and removed directories. */
\r
966 - for (i = 0; i < num_fs_entries; i++)
\r
971 - entry = fs_entries[i];
\r
973 - /* Check if we've walked past any names in db_files or
\r
974 - * db_subdirs. If so, these have been deleted. */
\r
975 - while (notmuch_filenames_valid (db_files) &&
\r
976 - strcmp (notmuch_filenames_get (db_files), entry->d_name) < 0)
\r
978 - char *absolute = talloc_asprintf (state->removed_files,
\r
980 - notmuch_filenames_get (db_files));
\r
982 - _filename_list_add (state->removed_files, absolute);
\r
984 - notmuch_filenames_move_to_next (db_files);
\r
987 - while (notmuch_filenames_valid (db_subdirs) &&
\r
988 - strcmp (notmuch_filenames_get (db_subdirs), entry->d_name) <= 0)
\r
990 - const char *filename = notmuch_filenames_get (db_subdirs);
\r
992 - if (strcmp (filename, entry->d_name) < 0)
\r
994 - char *absolute = talloc_asprintf (state->removed_directories,
\r
995 - "%s/%s", path, filename);
\r
997 - _filename_list_add (state->removed_directories, absolute);
\r
1000 - notmuch_filenames_move_to_next (db_subdirs);
\r
1003 - /* If we're looking at a symlink, we only want to add it if it
\r
1004 - * links to a regular file, (and not to a directory, say).
\r
1006 - * Similarly, if the file is of unknown type (due to filesytem
\r
1007 - * limitations), then we also need to look closer.
\r
1009 - * In either case, a stat does the trick.
\r
1011 - if (entry->d_type == DT_LNK || entry->d_type == DT_UNKNOWN) {
\r
1014 - next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
\r
1015 - err = stat (next, &st);
\r
1016 - talloc_free (next);
\r
1019 - /* Don't emit an error for a link pointing nowhere, since
\r
1020 - * the directory-traversal pass will have already done
\r
1025 - if (! S_ISREG (st.st_mode))
\r
1027 - } else if (entry->d_type != DT_REG) {
\r
1031 - /* Don't add a file that we've added before. */
\r
1032 - if (notmuch_filenames_valid (db_files) &&
\r
1033 - strcmp (notmuch_filenames_get (db_files), entry->d_name) == 0)
\r
1035 - notmuch_filenames_move_to_next (db_files);
\r
1039 - /* We're now looking at a regular file that doesn't yet exist
\r
1040 - * in the database, so add it. */
\r
1041 - next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
\r
1043 - state->processed_files++;
\r
1045 - if (state->verbose) {
\r
1046 - if (state->output_is_a_tty)
\r
1047 - printf("\r\033[K");
\r
1049 - printf ("%i/%i: %s",
\r
1050 - state->processed_files,
\r
1051 - state->total_files,
\r
1054 - putchar((state->output_is_a_tty) ? '\r' : '\n');
\r
1055 - fflush (stdout);
\r
1058 - status = notmuch_database_add_message (notmuch, next, &message);
\r
1059 - switch (status) {
\r
1061 - case NOTMUCH_STATUS_SUCCESS:
\r
1062 - state->added_messages++;
\r
1063 - tag_inbox_and_unread (message);
\r
1065 - /* Non-fatal issues (go on to next file) */
\r
1066 - case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
\r
1067 - /* Stay silent on this one. */
\r
1069 - case NOTMUCH_STATUS_FILE_NOT_EMAIL:
\r
1070 - fprintf (stderr, "Note: Ignoring non-mail file: %s\n",
\r
1073 - /* Fatal issues. Don't process anymore. */
\r
1074 - case NOTMUCH_STATUS_READ_ONLY_DATABASE:
\r
1075 - case NOTMUCH_STATUS_XAPIAN_EXCEPTION:
\r
1076 - case NOTMUCH_STATUS_OUT_OF_MEMORY:
\r
1077 - fprintf (stderr, "Error: %s. Halting processing.\n",
\r
1078 - notmuch_status_to_string (status));
\r
1082 - case NOTMUCH_STATUS_FILE_ERROR:
\r
1083 - case NOTMUCH_STATUS_NULL_POINTER:
\r
1084 - case NOTMUCH_STATUS_TAG_TOO_LONG:
\r
1085 - case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:
\r
1086 - case NOTMUCH_STATUS_LAST_STATUS:
\r
1087 - INTERNAL_ERROR ("add_message returned unexpected value: %d", status);
\r
1092 - notmuch_message_destroy (message);
\r
1096 - if (do_add_files_print_progress) {
\r
1097 - do_add_files_print_progress = 0;
\r
1098 - add_files_print_progress (state);
\r
1101 - talloc_free (next);
\r
1105 - /* Now that we've walked the whole filesystem list, anything left
\r
1106 - * over in the database lists has been deleted. */
\r
1107 - while (notmuch_filenames_valid (db_files))
\r
1109 - char *absolute = talloc_asprintf (state->removed_files,
\r
1111 - notmuch_filenames_get (db_files));
\r
1113 - _filename_list_add (state->removed_files, absolute);
\r
1115 - notmuch_filenames_move_to_next (db_files);
\r
1118 - while (notmuch_filenames_valid (db_subdirs))
\r
1120 - char *absolute = talloc_asprintf (state->removed_directories,
\r
1122 - notmuch_filenames_get (db_subdirs));
\r
1124 - _filename_list_add (state->removed_directories, absolute);
\r
1126 - notmuch_filenames_move_to_next (db_subdirs);
\r
1129 - if (! interrupted) {
\r
1130 - status = notmuch_directory_set_mtime (directory, fs_mtime);
\r
1131 - if (status && ret == NOTMUCH_STATUS_SUCCESS)
\r
1137 - talloc_free (next);
\r
1143 - free (fs_entries);
\r
1145 - notmuch_filenames_destroy (db_subdirs);
\r
1147 - notmuch_filenames_destroy (db_files);
\r
1149 - notmuch_directory_destroy (directory);
\r
1154 /* This is the top-level entry point for add_files. It does a couple
\r
1155 * of error checks, sets up the progress-printing timer and then calls
\r
1156 * into the recursive function. */
\r
1157 static notmuch_status_t
\r
1158 -add_files (notmuch_database_t *notmuch,
\r
1159 +add_files (notmuch_mailstore_t *mailstore,
\r
1161 - add_files_state_t *state)
\r
1162 + notmuch_indexing_context_t *state) /* FIXME: rename */
\r
1164 notmuch_status_t status;
\r
1165 struct sigaction action;
\r
1166 @@ -517,6 +84,9 @@ add_files (notmuch_database_t *notmuch,
\r
1167 notmuch_bool_t timer_is_active = FALSE;
\r
1170 + state->print_progress = 0;
\r
1171 + state->print_progress_cb = add_files_print_progress;
\r
1173 if (state->output_is_a_tty && ! debugger_is_active () && ! state->verbose) {
\r
1174 /* Setup our handler for SIGALRM */
\r
1175 memset (&action, 0, sizeof (struct sigaction));
\r
1176 @@ -546,7 +116,7 @@ add_files (notmuch_database_t *notmuch,
\r
1177 return NOTMUCH_STATUS_FILE_ERROR;
\r
1180 - status = add_files_recursive (notmuch, path, state);
\r
1181 + status = notmuch_mailstore_index_new (mailstore, path, state);
\r
1183 if (timer_is_active) {
\r
1184 /* Now stop the timer. */
\r
1185 @@ -564,80 +134,11 @@ add_files (notmuch_database_t *notmuch,
\r
1189 -/* XXX: This should be merged with the add_files function since it
\r
1190 - * shares a lot of logic with it. */
\r
1191 -/* Recursively count all regular files in path and all sub-directories
\r
1192 - * of path. The result is added to *count (which should be
\r
1193 - * initialized to zero by the top-level caller before calling
\r
1194 - * count_files). */
\r
1196 -count_files (const char *path, int *count)
\r
1198 - struct dirent *entry = NULL;
\r
1201 - struct dirent **fs_entries = NULL;
\r
1202 - int num_fs_entries = scandir (path, &fs_entries, 0, dirent_sort_inode);
\r
1205 - if (num_fs_entries == -1) {
\r
1206 - fprintf (stderr, "Warning: failed to open directory %s: %s\n",
\r
1207 - path, strerror (errno));
\r
1211 - while (!interrupted) {
\r
1212 - if (i == num_fs_entries)
\r
1215 - entry = fs_entries[i++];
\r
1217 - /* Ignore special directories to avoid infinite recursion.
\r
1218 - * Also ignore the .notmuch directory.
\r
1220 - /* XXX: Eventually we'll want more sophistication to let the
\r
1221 - * user specify files to be ignored. */
\r
1222 - if (strcmp (entry->d_name, ".") == 0 ||
\r
1223 - strcmp (entry->d_name, "..") == 0 ||
\r
1224 - strcmp (entry->d_name, ".notmuch") == 0)
\r
1229 - if (asprintf (&next, "%s/%s", path, entry->d_name) == -1) {
\r
1231 - fprintf (stderr, "Error descending from %s to %s: Out of memory\n",
\r
1232 - path, entry->d_name);
\r
1236 - stat (next, &st);
\r
1238 - if (S_ISREG (st.st_mode)) {
\r
1239 - *count = *count + 1;
\r
1240 - if (*count % 1000 == 0) {
\r
1241 - printf ("Found %d files so far.\r", *count);
\r
1242 - fflush (stdout);
\r
1244 - } else if (S_ISDIR (st.st_mode)) {
\r
1245 - count_files (next, count);
\r
1255 - free (fs_entries);
\r
1259 upgrade_print_progress (void *closure,
\r
1262 - add_files_state_t *state = closure;
\r
1263 + notmuch_indexing_context_t *state = closure;
\r
1265 printf ("Upgrading database: %.2f%% complete", progress * 100.0);
\r
1267 @@ -659,55 +160,12 @@ upgrade_print_progress (void *closure,
\r
1271 -/* Recursively remove all filenames from the database referring to
\r
1272 - * 'path' (or to any of its children). */
\r
1274 -_remove_directory (void *ctx,
\r
1275 - notmuch_database_t *notmuch,
\r
1276 - const char *path,
\r
1277 - int *renamed_files,
\r
1278 - int *removed_files)
\r
1280 - notmuch_directory_t *directory;
\r
1281 - notmuch_filenames_t *files, *subdirs;
\r
1282 - notmuch_status_t status;
\r
1285 - directory = notmuch_database_get_directory (notmuch, path);
\r
1287 - for (files = notmuch_directory_get_child_files (directory);
\r
1288 - notmuch_filenames_valid (files);
\r
1289 - notmuch_filenames_move_to_next (files))
\r
1291 - absolute = talloc_asprintf (ctx, "%s/%s", path,
\r
1292 - notmuch_filenames_get (files));
\r
1293 - status = notmuch_database_remove_message (notmuch, absolute);
\r
1294 - if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
\r
1295 - *renamed_files = *renamed_files + 1;
\r
1297 - *removed_files = *removed_files + 1;
\r
1298 - talloc_free (absolute);
\r
1301 - for (subdirs = notmuch_directory_get_child_directories (directory);
\r
1302 - notmuch_filenames_valid (subdirs);
\r
1303 - notmuch_filenames_move_to_next (subdirs))
\r
1305 - absolute = talloc_asprintf (ctx, "%s/%s", path,
\r
1306 - notmuch_filenames_get (subdirs));
\r
1307 - _remove_directory (ctx, notmuch, absolute, renamed_files, removed_files);
\r
1308 - talloc_free (absolute);
\r
1311 - notmuch_directory_destroy (directory);
\r
1315 notmuch_new_command (void *ctx, int argc, char *argv[])
\r
1317 notmuch_config_t *config;
\r
1318 notmuch_database_t *notmuch;
\r
1319 - add_files_state_t add_files_state;
\r
1320 + notmuch_indexing_context_t add_files_state; /* FIXME: Rename */
\r
1322 struct timeval tv_now;
\r
1324 @@ -715,10 +173,10 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
1325 const char *db_path;
\r
1326 char *dot_notmuch_path;
\r
1327 struct sigaction action;
\r
1328 - _filename_node_t *f;
\r
1329 - int renamed_files, removed_files;
\r
1330 - notmuch_status_t status;
\r
1332 + notmuch_mailstore_t *mailstore;
\r
1334 + indexing_ctx = &add_files_state;
\r
1336 add_files_state.verbose = 0;
\r
1337 add_files_state.output_is_a_tty = isatty (fileno (stdout));
\r
1338 @@ -737,6 +195,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
1341 db_path = notmuch_config_get_database_path (config);
\r
1342 + mailstore = notmuch_config_get_mailstore (config);
\r
1344 dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");
\r
1346 @@ -744,7 +203,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
1350 - count_files (db_path, &count);
\r
1351 + notmuch_mailstore_count_files (mailstore, db_path, &count, &interrupted);
\r
1355 @@ -777,6 +236,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
1356 /* Setup our handler for SIGINT. We do this after having
\r
1357 * potentially done a database upgrade we this interrupt handler
\r
1358 * won't support. */
\r
1359 + add_files_state.interrupted = 0;
\r
1360 memset (&action, 0, sizeof (struct sigaction));
\r
1361 action.sa_handler = handle_sigint;
\r
1362 sigemptyset (&action.sa_mask);
\r
1363 @@ -790,28 +250,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
1364 add_files_state.added_messages = 0;
\r
1365 gettimeofday (&add_files_state.tv_start, NULL);
\r
1367 - add_files_state.removed_files = _filename_list_create (ctx);
\r
1368 - add_files_state.removed_directories = _filename_list_create (ctx);
\r
1370 - ret = add_files (notmuch, db_path, &add_files_state);
\r
1372 - removed_files = 0;
\r
1373 - renamed_files = 0;
\r
1374 - for (f = add_files_state.removed_files->head; f; f = f->next) {
\r
1375 - status = notmuch_database_remove_message (notmuch, f->filename);
\r
1376 - if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
\r
1377 - renamed_files++;
\r
1379 - removed_files++;
\r
1382 - for (f = add_files_state.removed_directories->head; f; f = f->next) {
\r
1383 - _remove_directory (ctx, notmuch, f->filename,
\r
1384 - &renamed_files, &removed_files);
\r
1387 - talloc_free (add_files_state.removed_files);
\r
1388 - talloc_free (add_files_state.removed_directories);
\r
1389 + ret = add_files (mailstore, db_path, &add_files_state);
\r
1391 gettimeofday (&tv_now, NULL);
\r
1392 elapsed = notmuch_time_elapsed (add_files_state.tv_start,
\r
1393 @@ -839,16 +278,16 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
1394 printf ("No new mail.");
\r
1397 - if (removed_files) {
\r
1398 + if (add_files_state.removed_files) {
\r
1399 printf (" Removed %d %s.",
\r
1401 - removed_files == 1 ? "message" : "messages");
\r
1402 + add_files_state.removed_files,
\r
1403 + add_files_state.removed_files == 1 ? "message" : "messages");
\r
1406 - if (renamed_files) {
\r
1407 + if (add_files_state.renamed_files) {
\r
1408 printf (" Detected %d file %s.",
\r
1410 - renamed_files == 1 ? "rename" : "renames");
\r
1411 + add_files_state.renamed_files,
\r
1412 + add_files_state.renamed_files == 1 ? "rename" : "renames");
\r