From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id A3700431FBC for ; Wed, 2 Dec 2009 13:15:32 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FoTs+tuwF+-g for ; Wed, 2 Dec 2009 13:15:31 -0800 (PST) Received: from dottedmag.net (burger.dottedmag.net [212.75.37.82]) by olra.theworths.org (Postfix) with ESMTP id 5B809431FAE for ; Wed, 2 Dec 2009 13:15:31 -0800 (PST) Received: from vertex.dottedmag (unknown [91.197.127.125]) by dottedmag.net (Postfix) with ESMTPSA id 700028C9BF for ; Wed, 2 Dec 2009 22:15:29 +0100 (CET) Received: from dottedmag by vertex.dottedmag with local (Exim 4.69) (envelope-from ) id 1NFwXm-0003hd-Se for notmuch@notmuchmail.org; Thu, 03 Dec 2009 03:15:26 +0600 From: Mikhail Gusarov To: notmuch@notmuchmail.org Date: Thu, 3 Dec 2009 03:15:26 +0600 Message-Id: <1259788526-14205-1-git-send-email-dottedmag@dottedmag.net> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1259267025-28733-1-git-send-email-dottedmag@dottedmag.net> References: <1259267025-28733-1-git-send-email-dottedmag@dottedmag.net> Subject: [PATCH (rebased)] Handle message renames in mail spool X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Dec 2009 21:15:32 -0000 In order to handle message renames the following changes were deemed necessary: * Mtime check on individual files was disabled. As files may be moved around without changing their mtime, it's necessary to parse them even if they appear old in case old message was moved. mtime check on directories was kept as moving files changes mtime of directory. * If message being parsed is already found in database under different path, then this message is considered to be moved, path is updated in database and this file does not undergo further processing. Note that after applying this patch notmuch still does not handle copying files (which is harmless, database will point to the last copy of message found during 'notmuch new') and deleting files (which is more serious, as dangling entries will show up in searches). Signed-off-by: Mikhail Gusarov --- lib/database.cc | 32 ++++++++++----- notmuch-new.c | 116 ++++++++++++++++++++++++++---------------------------- 2 files changed, 78 insertions(+), 70 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index 23ddd4a..45d8fc7 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -993,19 +993,31 @@ notmuch_database_add_message (notmuch_database_t *notmuch, if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) { _notmuch_message_set_filename (message, filename); _notmuch_message_add_term (message, "type", "mail"); - } else { - ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID; - goto DONE; - } - ret = _notmuch_database_link_message (notmuch, message, message_file); - if (ret) - goto DONE; + ret = _notmuch_database_link_message (notmuch, message, message_file); + if (ret) + goto DONE; - date = notmuch_message_file_get_header (message_file, "date"); - _notmuch_message_set_date (message, date); + date = notmuch_message_file_get_header (message_file, "date"); + _notmuch_message_set_date (message, date); - _notmuch_message_index_file (message, filename); + _notmuch_message_index_file (message, filename); + } else { + const char *old_filename = notmuch_message_get_filename (message); + if (strcmp (old_filename, filename) == 0) { + /* We have already seen it */ + goto DONE; + } else { + if (access (old_filename, R_OK) == 0) { + /* old_filename still exists, we've got a duplicate */ + ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID; + goto DONE; + } else { + /* Message file has been moved/renamed */ + _notmuch_message_set_filename (message, filename); + } + } + } _notmuch_message_sync (message); } catch (const Xapian::Error &error) { diff --git a/notmuch-new.c b/notmuch-new.c index 9d20616..d595fc4 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -217,66 +217,62 @@ add_files_recursive (notmuch_database_t *notmuch, } if (S_ISREG (st->st_mode)) { - /* If the file hasn't been modified since the last - * add_files, then we need not look at it. */ - if (path_dbtime == 0 || st->st_mtime > path_dbtime) { - state->processed_files++; - - if (state->verbose) { - if (state->output_is_a_tty) - printf("\r\033[K"); - - printf ("%i/%i: %s", - state->processed_files, - state->total_files, - next); - - putchar((state->output_is_a_tty) ? '\r' : '\n'); - fflush (stdout); - } - - status = notmuch_database_add_message (notmuch, next, &message); - switch (status) { - /* success */ - case NOTMUCH_STATUS_SUCCESS: - state->added_messages++; - tag_inbox_and_unread (message); - break; - /* Non-fatal issues (go on to next file) */ - case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: - /* Stay silent on this one. */ - break; - case NOTMUCH_STATUS_FILE_NOT_EMAIL: - fprintf (stderr, "Note: Ignoring non-mail file: %s\n", - next); - break; - /* Fatal issues. Don't process anymore. */ - case NOTMUCH_STATUS_READONLY_DATABASE: - case NOTMUCH_STATUS_XAPIAN_EXCEPTION: - case NOTMUCH_STATUS_OUT_OF_MEMORY: - fprintf (stderr, "Error: %s. Halting processing.\n", - notmuch_status_to_string (status)); - ret = status; - goto DONE; - default: - case NOTMUCH_STATUS_FILE_ERROR: - case NOTMUCH_STATUS_NULL_POINTER: - case NOTMUCH_STATUS_TAG_TOO_LONG: - case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW: - case NOTMUCH_STATUS_LAST_STATUS: - INTERNAL_ERROR ("add_message returned unexpected value: %d", status); - goto DONE; - } - - if (message) { - notmuch_message_destroy (message); - message = NULL; - } - - if (do_add_files_print_progress) { - do_add_files_print_progress = 0; - add_files_print_progress (state); - } + state->processed_files++; + + if (state->verbose) { + if (state->output_is_a_tty) + printf("\r\033[K"); + + printf ("%i/%i: %s", + state->processed_files, + state->total_files, + next); + + putchar((state->output_is_a_tty) ? '\r' : '\n'); + fflush (stdout); + } + + status = notmuch_database_add_message (notmuch, next, &message); + switch (status) { + /* success */ + case NOTMUCH_STATUS_SUCCESS: + state->added_messages++; + tag_inbox_and_unread (message); + break; + /* Non-fatal issues (go on to next file) */ + case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: + /* Stay silent on this one. */ + break; + case NOTMUCH_STATUS_FILE_NOT_EMAIL: + fprintf (stderr, "Note: Ignoring non-mail file: %s\n", + next); + break; + /* Fatal issues. Don't process anymore. */ + case NOTMUCH_STATUS_READONLY_DATABASE: + case NOTMUCH_STATUS_XAPIAN_EXCEPTION: + case NOTMUCH_STATUS_OUT_OF_MEMORY: + fprintf (stderr, "Error: %s. Halting processing.\n", + notmuch_status_to_string (status)); + ret = status; + goto DONE; + default: + case NOTMUCH_STATUS_FILE_ERROR: + case NOTMUCH_STATUS_NULL_POINTER: + case NOTMUCH_STATUS_TAG_TOO_LONG: + case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW: + case NOTMUCH_STATUS_LAST_STATUS: + INTERNAL_ERROR ("add_message returned unexpected value: %d", status); + goto DONE; + } + + if (message) { + notmuch_message_destroy (message); + message = NULL; + } + + if (do_add_files_print_progress) { + do_add_files_print_progress = 0; + add_files_print_progress (state); } } else if (S_ISDIR (st->st_mode)) { status = add_files_recursive (notmuch, next, st, state); -- 1.6.3.3