1 Return-Path: <amthrax@drake.mit.edu>
\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 C8790429E5B
\r
6 for <notmuch@notmuchmail.org>; Wed, 29 Jun 2011 00:11:00 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\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 TA3sJjnbHe35 for <notmuch@notmuchmail.org>;
\r
16 Wed, 29 Jun 2011 00:11:00 -0700 (PDT)
\r
17 Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id EAAF1429E55
\r
20 for <notmuch@notmuchmail.org>; Wed, 29 Jun 2011 00:10:59 -0700 (PDT)
\r
21 X-AuditID: 1209190c-b7c65ae00000117c-b2-4e0ad006ff12
\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])
\r
23 by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id 4F.31.04476.600DA0E4; Wed, 29 Jun 2011 03:11:02 -0400 (EDT)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id p5T7Aw3o002759;
\r
27 Wed, 29 Jun 2011 03:10:58 -0400
\r
28 Received: from drake.mit.edu
\r
29 (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com
\r
30 [209.6.116.242]) (authenticated bits=0)
\r
31 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
32 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p5T7AvxQ015204
\r
33 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
34 Wed, 29 Jun 2011 03:10:58 -0400 (EDT)
\r
35 Received: from amthrax by drake.mit.edu with local (Exim 4.76)
\r
36 (envelope-from <amthrax@drake.mit.edu>)
\r
37 id 1QbovJ-00056S-It; Wed, 29 Jun 2011 03:10:57 -0400
\r
38 From: Austin Clements <amdragon@MIT.EDU>
\r
39 To: notmuch@notmuchmail.org
\r
40 Subject: [PATCH 1/2] new: Don't update DB mtime if FS mtime equals wall-clock
\r
42 Date: Wed, 29 Jun 2011 03:10:54 -0400
\r
43 Message-Id: <1309331455-19584-1-git-send-email-amdragon@mit.edu>
\r
44 X-Mailer: git-send-email 1.7.5.1
\r
45 X-Brightmail-Tracker:
\r
46 H4sIAAAAAAAAA+NgFlrCIsWRmVeSWpSXmKPExsUixCmqrMt2gcvPYOkVQ4vrN2cyOzB6PFt1
\r
47 izmAMYrLJiU1J7MstUjfLoEr49Lb9ewFsyUqLjcsYWpgfCfUxcjJISFgItG8r50VwhaTuHBv
\r
48 PVsXIxeHkMA+RokNRzoYQRJCAhsYJQ42ykEk7jNJ3FvwEKpqPqNEx8RFzCBVbAIaEtv2Lwfr
\r
49 EBGQlth5dzbQWA4OZgERiXczmUBMYYFgifv/80FMFgFVic3fYkGKeQUcJC58vMsCcYOCxJUr
\r
50 81gmMPIuYGRYxSibklulm5uYmVOcmqxbnJyYl5dapGuol5tZopeaUrqJERwAkjw7GN8cVDrE
\r
51 KMDBqMTDm/mU00+INbGsuDL3EKMkB5OSKG/MWS4/Ib6k/JTKjMTijPii0pzU4kOMEhzMSiK8
\r
52 vxcA5XhTEiurUovyYVLSHCxK4rzl3v99hQTSE0tSs1NTC1KLYLIyHBxKErwTzgE1ChalpqdW
\r
53 pGXmlCCkmTg4QYbzAA33A6nhLS5IzC3OTIfIn2LU5Xj7euVhRiGWvPy8VClx3i0gRQIgRRml
\r
54 eXBzYJH7ilEc6C1h3g6QKh5g1MNNegW0hAloyYUosCUliQgpqQbGkimGFY7HFgg31db/4KqP
\r
55 Pjs7dMK1ONH4xFk5h3lnVf5VY779my/RW/jU6cSjD47ucFjotuWkt+qC0PsrLU9csT/083vm
\r
56 RFOee4vNgkMz/7+Ijw79duf/RY7ikHWV6QHLlv24yeN1a2NF843OtTMqlsevbcy76s5yNszf
\r
57 8Y5k1Wvj1cu4Lj3jUGIpzkg01GIuKk4EAAB5bq63AgAA
\r
58 Cc: amdragon@mit.edu
\r
59 X-BeenThere: notmuch@notmuchmail.org
\r
60 X-Mailman-Version: 2.1.13
\r
62 List-Id: "Use and development of the notmuch mail system."
\r
63 <notmuch.notmuchmail.org>
\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
65 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
67 List-Post: <mailto:notmuch@notmuchmail.org>
\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
70 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
71 X-List-Received-Date: Wed, 29 Jun 2011 07:11:01 -0000
\r
73 This fixes a race where multiple message deliveries in the same second
\r
74 with an intervening notmuch new could result in messages being ignored
\r
75 by notmuch (at least, until a later delivery forced a rescan).
\r
76 Because mtimes only have second granularity, later deliveries in the
\r
77 same second won't change the directory mtime, and hence won't trigger
\r
78 notmuch new to rescan the directory. This situation can only occur
\r
79 when notmuch new is being run at the same second as the directory's
\r
80 modification time, so simply don't update the saved mtime in this
\r
83 This very race happens all over the test suite, and is currently
\r
84 compensated for with increment_mtime (and, occasionally, luck). With
\r
85 this change, increment_mtime becomes unnecessary.
\r
87 notmuch-new.c | 20 +++++++++++++++++++-
\r
88 1 files changed, 19 insertions(+), 1 deletions(-)
\r
90 diff --git a/notmuch-new.c b/notmuch-new.c
\r
91 index 0fa2a3c..c180591 100644
\r
94 @@ -213,6 +213,7 @@ _entries_resemble_maildir (struct dirent **entries, int count)
\r
95 * information is lost from the database).
\r
97 * o Tell the database to update its time of 'path' to 'fs_mtime'
\r
98 + * if fs_mtime isn't the current wall-clock time.
\r
100 static notmuch_status_t
\r
101 add_files_recursive (notmuch_database_t *notmuch,
\r
102 @@ -230,6 +231,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
103 notmuch_directory_t *directory;
\r
104 notmuch_filenames_t *db_files = NULL;
\r
105 notmuch_filenames_t *db_subdirs = NULL;
\r
106 + time_t stat_time;
\r
108 notmuch_bool_t is_maildir, new_directory;
\r
110 @@ -239,6 +241,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
111 path, strerror (errno));
\r
112 return NOTMUCH_STATUS_FILE_ERROR;
\r
114 + stat_time = time (NULL);
\r
116 /* This is not an error since we may have recursed based on a
\r
117 * symlink to a regular file, not a directory, and we don't know
\r
118 @@ -509,7 +512,22 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
119 notmuch_filenames_move_to_next (db_subdirs);
\r
122 - if (! interrupted) {
\r
123 + /* If the directory's mtime is the same as the wall-clock time
\r
124 + * when we stat'ed the directory, we skip updating the mtime in
\r
125 + * the database because a message could be delivered later in this
\r
126 + * same second. This may lead to unnecessary re-scans, but it
\r
127 + * avoids overlooking messages.
\r
129 + * XXX Bug workaround: If this is a new directory, we *must*
\r
130 + * update the mtime; otherwise the next run will see the 0 mtime
\r
131 + * and think this is still a new directory containing no files or
\r
132 + * subdirs (which is unsound in general). If fs_mtime ==
\r
133 + * stat_time, we set the database mtime to a bogus (but non-zero!)
\r
134 + * value to force a rescan.
\r
136 + if (new_directory && fs_mtime == stat_time)
\r
138 + if (! interrupted && fs_mtime != stat_time) {
\r
139 status = notmuch_directory_set_mtime (directory, fs_mtime);
\r
140 if (status && ret == NOTMUCH_STATUS_SUCCESS)
\r