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