--- /dev/null
+Return-Path: <amthrax@drake.mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id C8790429E5B\r
+ for <notmuch@notmuchmail.org>; Wed, 29 Jun 2011 00:11:00 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id TA3sJjnbHe35 for <notmuch@notmuchmail.org>;\r
+ Wed, 29 Jun 2011 00:11:00 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU\r
+ [18.9.25.12])\r
+ by olra.theworths.org (Postfix) with ESMTP id EAAF1429E55\r
+ for <notmuch@notmuchmail.org>; Wed, 29 Jun 2011 00:10:59 -0700 (PDT)\r
+X-AuditID: 1209190c-b7c65ae00000117c-b2-4e0ad006ff12\r
+Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
+ by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 4F.31.04476.600DA0E4; Wed, 29 Jun 2011 03:11:02 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+ by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id p5T7Aw3o002759; \r
+ Wed, 29 Jun 2011 03:10:58 -0400\r
+Received: from drake.mit.edu\r
+ (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+ [209.6.116.242]) (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p5T7AvxQ015204\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Wed, 29 Jun 2011 03:10:58 -0400 (EDT)\r
+Received: from amthrax by drake.mit.edu with local (Exim 4.76)\r
+ (envelope-from <amthrax@drake.mit.edu>)\r
+ id 1QbovJ-00056S-It; Wed, 29 Jun 2011 03:10:57 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/2] new: Don't update DB mtime if FS mtime equals wall-clock\r
+ time.\r
+Date: Wed, 29 Jun 2011 03:10:54 -0400\r
+Message-Id: <1309331455-19584-1-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.5.1\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFlrCIsWRmVeSWpSXmKPExsUixCmqrMt2gcvPYOkVQ4vrN2cyOzB6PFt1\r
+ izmAMYrLJiU1J7MstUjfLoEr49Lb9ewFsyUqLjcsYWpgfCfUxcjJISFgItG8r50VwhaTuHBv\r
+ PVsXIxeHkMA+RokNRzoYQRJCAhsYJQ42ykEk7jNJ3FvwEKpqPqNEx8RFzCBVbAIaEtv2Lwfr\r
+ EBGQlth5dzbQWA4OZgERiXczmUBMYYFgifv/80FMFgFVic3fYkGKeQUcJC58vMsCcYOCxJUr\r
+ 81gmMPIuYGRYxSibklulm5uYmVOcmqxbnJyYl5dapGuol5tZopeaUrqJERwAkjw7GN8cVDrE\r
+ KMDBqMTDm/mU00+INbGsuDL3EKMkB5OSKG/MWS4/Ib6k/JTKjMTijPii0pzU4kOMEhzMSiK8\r
+ vxcA5XhTEiurUovyYVLSHCxK4rzl3v99hQTSE0tSs1NTC1KLYLIyHBxKErwTzgE1ChalpqdW\r
+ pGXmlCCkmTg4QYbzAA33A6nhLS5IzC3OTIfIn2LU5Xj7euVhRiGWvPy8VClx3i0gRQIgRRml\r
+ eXBzYJH7ilEc6C1h3g6QKh5g1MNNegW0hAloyYUosCUliQgpqQbGkimGFY7HFgg31db/4KqP\r
+ Pjs7dMK1ONH4xFk5h3lnVf5VY779my/RW/jU6cSjD47ucFjotuWkt+qC0PsrLU9csT/083vm\r
+ RFOee4vNgkMz/7+Ijw79duf/RY7ikHWV6QHLlv24yeN1a2NF843OtTMqlsevbcy76s5yNszf\r
+ 8Y5k1Wvj1cu4Lj3jUGIpzkg01GIuKk4EAAB5bq63AgAA\r
+Cc: amdragon@mit.edu\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Wed, 29 Jun 2011 07:11:01 -0000\r
+\r
+This fixes a race where multiple message deliveries in the same second\r
+with an intervening notmuch new could result in messages being ignored\r
+by notmuch (at least, until a later delivery forced a rescan).\r
+Because mtimes only have second granularity, later deliveries in the\r
+same second won't change the directory mtime, and hence won't trigger\r
+notmuch new to rescan the directory. This situation can only occur\r
+when notmuch new is being run at the same second as the directory's\r
+modification time, so simply don't update the saved mtime in this\r
+case.\r
+\r
+This very race happens all over the test suite, and is currently\r
+compensated for with increment_mtime (and, occasionally, luck). With\r
+this change, increment_mtime becomes unnecessary.\r
+---\r
+ notmuch-new.c | 20 +++++++++++++++++++-\r
+ 1 files changed, 19 insertions(+), 1 deletions(-)\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index 0fa2a3c..c180591 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -213,6 +213,7 @@ _entries_resemble_maildir (struct dirent **entries, int count)\r
+ * information is lost from the database).\r
+ *\r
+ * o Tell the database to update its time of 'path' to 'fs_mtime'\r
++ * if fs_mtime isn't the current wall-clock time.\r
+ */\r
+ static notmuch_status_t\r
+ add_files_recursive (notmuch_database_t *notmuch,\r
+@@ -230,6 +231,7 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+ notmuch_directory_t *directory;\r
+ notmuch_filenames_t *db_files = NULL;\r
+ notmuch_filenames_t *db_subdirs = NULL;\r
++ time_t stat_time;\r
+ struct stat st;\r
+ notmuch_bool_t is_maildir, new_directory;\r
+ const char **tag;\r
+@@ -239,6 +241,7 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+ path, strerror (errno));\r
+ return NOTMUCH_STATUS_FILE_ERROR;\r
+ }\r
++ stat_time = time (NULL);\r
+ \r
+ /* This is not an error since we may have recursed based on a\r
+ * symlink to a regular file, not a directory, and we don't know\r
+@@ -509,7 +512,22 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+ notmuch_filenames_move_to_next (db_subdirs);\r
+ }\r
+ \r
+- if (! interrupted) {\r
++ /* If the directory's mtime is the same as the wall-clock time\r
++ * when we stat'ed the directory, we skip updating the mtime in\r
++ * the database because a message could be delivered later in this\r
++ * same second. This may lead to unnecessary re-scans, but it\r
++ * avoids overlooking messages.\r
++ *\r
++ * XXX Bug workaround: If this is a new directory, we *must*\r
++ * update the mtime; otherwise the next run will see the 0 mtime\r
++ * and think this is still a new directory containing no files or\r
++ * subdirs (which is unsound in general). If fs_mtime ==\r
++ * stat_time, we set the database mtime to a bogus (but non-zero!)\r
++ * value to force a rescan.\r
++ */\r
++ if (new_directory && fs_mtime == stat_time)\r
++ fs_mtime = 1;\r
++ if (! interrupted && fs_mtime != stat_time) {\r
+ status = notmuch_directory_set_mtime (directory, fs_mtime);\r
+ if (status && ret == NOTMUCH_STATUS_SUCCESS)\r
+ ret = status;\r
+-- \r
+1.7.5.1\r
+\r