aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/corpus/cur/10:2,
blob: 4211d7348b3b8fce48045ff4fa996d415e7f8522 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
From: "Mikhail Gusarov" <dottedmag@dottedmag.net>
To: notmuch@notmuchmail.org
Date: Wed, 18 Nov 2009 02:51:18 +0600
Subject: [notmuch] [PATCH] Handle rename of message file
Message-ID: <1258491078-29658-1-git-send-email-dottedmag@dottedmag.net>

If message file has been renamed, just update filename in the DB.

Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>
---
 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