Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id DE52D431FBC for ; Tue, 17 Nov 2009 12:51:20 -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 vSNyQAFba5ed for ; Tue, 17 Nov 2009 12:51:20 -0800 (PST) Received: from dottedmag.net (burger.dottedmag.net [212.75.37.82]) by olra.theworths.org (Postfix) with ESMTP id 40D02431FAE for ; Tue, 17 Nov 2009 12:51:20 -0800 (PST) Received: from vertex.dottedmag (unknown [91.197.127.125]) by dottedmag.net (Postfix) with ESMTPSA id 923208C03E for ; Tue, 17 Nov 2009 21:51:19 +0100 (CET) Received: from dottedmag by vertex.dottedmag with local (Exim 4.69) (envelope-from ) id 1NAV1C-0007is-8Z for notmuch@notmuchmail.org; Wed, 18 Nov 2009 02:51:18 +0600 From: Mikhail Gusarov To: notmuch@notmuchmail.org Date: Wed, 18 Nov 2009 02:51:18 +0600 Message-Id: <1258491078-29658-1-git-send-email-dottedmag@dottedmag.net> X-Mailer: git-send-email 1.6.3.3 Subject: [notmuch] [PATCH] Handle rename of message file 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: Tue, 17 Nov 2009 20:51:21 -0000 If message file has been renamed, just update filename in the DB. Signed-off-by: Mikhail Gusarov --- lib/database.cc | 21 ++++++++++++--------- 1 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index 3c8d626..c4eb8b6 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -925,20 +925,23 @@ 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"); + + 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); + + _notmuch_message_index_file (message, filename); + } else if (strcmp(notmuch_message_get_filename(message), filename)) { + /* Message file has been moved/renamed */ + _notmuch_message_set_filename (message, filename); } else { ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID; 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); - - _notmuch_message_index_file (message, filename); - _notmuch_message_sync (message); } catch (const Xapian::Error &error) { fprintf (stderr, "A Xapian exception occurred: %s.\n", -- 1.6.3.3