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 CAD5842119B for ; Wed, 29 Jun 2011 16:00:07 -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 pGclJv+-x8O4 for ; Wed, 29 Jun 2011 16:00:07 -0700 (PDT) Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU [18.9.25.15]) by olra.theworths.org (Postfix) with ESMTP id 380E2421192 for ; Wed, 29 Jun 2011 16:00:07 -0700 (PDT) X-AuditID: 1209190f-b7c82ae000000a20-ac-4e0bae7bb60e Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP id ED.54.02592.B7EAB0E4; Wed, 29 Jun 2011 19:00:11 -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 p5TN06Eo015086; Wed, 29 Jun 2011 19:00:06 -0400 Received: from drake.mit.edu (26-4-166.dynamic.csail.mit.edu [18.26.4.166]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p5TN05DV000582 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Wed, 29 Jun 2011 19:00:06 -0400 (EDT) Received: from amthrax by drake.mit.edu with local (Exim 4.76) (envelope-from ) id 1Qc3jp-0004I0-2h; Wed, 29 Jun 2011 19:00:05 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH] new: Improved workaround for mistaken new directories Date: Wed, 29 Jun 2011 19:00:01 -0400 Message-Id: <1309388401-16437-1-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.5.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrOIsWRmVeSWpSXmKPExsUixCmqrFu9jtvPYP13AYvrN2cyOzB6PFt1 izmAMYrLJiU1J7MstUjfLoErY8/lNsaCGxIVbdeXszcw/hTqYuTkkBAwkTi2+xA7hC0mceHe erYuRi4OIYF9jBKPp89jhHA2MErMnnwDKnOcSeL9y2VMEM58RolDDxvA+tkENCS27V/OCGKL CEhL7Lw7m7WLkYODWUBE4t1MJpCwsICbxNJNS9hAbBYBVYk5Oz6AlfMKOEjM/DQZ6gwFiStX 5rFMYORdwMiwilE2JbdKNzcxM6c4NVm3ODkxLy+1SNdELzezRC81pXQTIzgMJPl3MH47qHSI UYCDUYmHd6ETt58Qa2JZcWXuIUZJDiYlUV6vtUAhvqT8lMqMxOKM+KLSnNTiQ4wSHMxKIrwV rkA53pTEyqrUonyYlDQHi5I4b7n3f18hgfTEktTs1NSC1CKYrAwHh5IErw/IUMGi1PTUirTM nBKENBMHJ8hwHqDhNSA1vMUFibnFmekQ+VOMuhwLNj49zCjEkpeflyolzjsVpEgApCijNA9u Dix+XzGKA70lzFsLUsUDjH24Sa+AljABLbkQxQWypCQRISXVwCh3pvQpz90SBR4xjfB/+Yz9 L+y1WGeeX3+7/ovP36Tpn2RO6K0vrMn+EiJquefYA4GXPm8aPm2aJri9U42l9pn74pkL88w8 Ygr/JB4/EJzkt7px32r9Be8uzZsmls066/PdpGQG+8j4/UJ3og7OfZb+XH+73EVtfz7V5tqc EpEWrR8N/w667VViKc5INNRiLipOBADdFo8rugIAAA== 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 23:00:07 -0000 Currently, notmuch new assumes any directory with a database mtime of 0 is new, but we don't set the mtime until after processing messages and subdirectories in that directory. Hence, anything that prevents the mtime update (such as an interruption or the wall-clock logic introduced in 8c39e8d6) will cause the next notmuch new to think the directory is still new. We work around this by setting the new directory's database mtime to -1 before scanning anything in the new directory. This also obviates the need for the workaround used in 8c39e8d6. --- notmuch-new.c | 31 ++++++++++++++++++++----------- 1 files changed, 20 insertions(+), 11 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index c180591..7d17793 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -256,6 +256,25 @@ add_files_recursive (notmuch_database_t *notmuch, new_directory = db_mtime ? FALSE : TRUE; + /* XXX This is a temporary workaround. If we don't update the + * database mtime until after processing messages in this + * directory, then a 0 mtime is *not* sufficient to indicate that + * this directory has no messages or subdirs in the database (for + * example, if an earlier run skipped the mtime update because + * fs_mtime == stat_time, or was interrupted before updating the + * mtime at the end). To address this, we record a (bogus) + * non-zero value before processing any child messages so that a + * later run won't mistake this for a new directory (and, for + * example, fail to detect removed files and subdirs). + * + * A better solution would be for notmuch_database_get_directory + * to indicate if it really created a new directory or not, either + * by a new out-argument, or by recording this information and + * providing an accessor. + */ + if (new_directory) + notmuch_directory_set_mtime (directory, -1); + /* If the database knows about this directory, then we sort based * on strcmp to match the database sorting. Otherwise, we can do * inode-based sorting for faster filesystem operation. */ @@ -516,17 +535,7 @@ add_files_recursive (notmuch_database_t *notmuch, * 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; + * avoids overlooking messages. */ if (! interrupted && fs_mtime != stat_time) { status = notmuch_directory_set_mtime (directory, fs_mtime); if (status && ret == NOTMUCH_STATUS_SUCCESS) -- 1.7.5.1