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 C59B1429E36 for ; Thu, 17 May 2012 21:13:57 -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 f6FsxONCc4Gh for ; Thu, 17 May 2012 21:13:56 -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 3BABA431E62 for ; Thu, 17 May 2012 21:13:53 -0700 (PDT) X-AuditID: 1209190f-b7f4f6d00000092b-3e-4fb5cc809aa4 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP id 18.3A.02347.08CC5BF4; Fri, 18 May 2012 00:13:52 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q4I4DpsS001785; Fri, 18 May 2012 00:13:51 -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 q4I4Doal026787 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Fri, 18 May 2012 00:13:51 -0400 (EDT) Received: from amthrax by drake.mit.edu with local (Exim 4.77) (envelope-from ) id 1SVEZa-0000z6-Ed; Fri, 18 May 2012 00:13:50 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 4/9] lib: Make notmuch_database_get_directory return NULL if the directory is not found Date: Fri, 18 May 2012 00:13:37 -0400 Message-Id: <1337314423-3702-5-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1337314423-3702-1-git-send-email-amdragon@mit.edu> References: <1337314423-3702-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrAIsWRmVeSWpSXmKPExsUixCmqrdtwZqu/wbp76hbXb85kdmD0eLbq FnMAYxSXTUpqTmZZapG+XQJXxrk7KQUfJSvO7etlaWDsF+1i5OSQEDCRaOhpYYawxSQu3FvP 1sXIxSEksI9R4tT5FiYIZwOjxM6Nm5ghnPtMEguvfoUqm8Uose/nWhaQfjYBDYlt+5czgtgi AtISO+/OZu1i5OBgFlCT+NOlAhIWFkiX+HpjIiNImEVAVeJWtzVImFfAXuLkww4WiCvkJZ7e 72MDKeEUcJCYdjwaJCwEVPLvQjPLBEb+BYwMqxhlU3KrdHMTM3OKU5N1i5MT8/JSi3RN9HIz S/RSU0o3MYIDRpJ/B+O3g0qHGAU4GJV4eHfM2eovxJpYVlyZe4hRkoNJSZT3+0mgEF9Sfkpl RmJxRnxRaU5q8SFGCQ5mJRFe2W6gHG9KYmVValE+TEqag0VJnFdN652fkEB6YklqdmpqQWoR TFaGg0NJgtfiNFCjYFFqempFWmZOCUKaiYMTZDgP0HAtkBre4oLE3OLMdIj8KUZFKXFeG5CE AEgiozQPrhcW0a8YxYFeEeYNBaniASYDuO5XQIOZgAaX5W4CGVySiJCSamBsuBLUJW3CUP1k 2YwXCWsnGqzu23f/4tmur0cO8LYuYPbI138+eRbnxhfFb5WDDr8/L/FPhF/X6OGHvJ1154xj Zq1kf9V8ZN9R7okaqhezd0yZE/upuuuL2i5xwbz+fG3x/TdiIi/1Ol1k6vyuPrvTblVOI0/O q52M3wr1lwsG5jwttxLKvfBKiaU4I9FQi7moOBEAuD00AcMCAAA= 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: Fri, 18 May 2012 04:13:58 -0000 Using the new support from _notmuch_directory_create, this makes notmuch_database_get_directory a read-only operation that simply returns the directory object if it exists or NULL otherwise. This also means that notmuch_database_get_directory can work on read-only databases. This change breaks the directory mtime workaround in notmuch-new.c by fixing the exact issue it was working around. This permits mtime update races to prevent scans of changed directories, which non-deterministically breaks a few tests. The next patch fixes this. --- lib/database.cc | 7 ++----- lib/notmuch-private.h | 3 +++ lib/notmuch.h | 10 ++-------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index b4c76b4..e27a0e1 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -1328,12 +1328,9 @@ notmuch_database_get_directory (notmuch_database_t *notmuch, return NOTMUCH_STATUS_NULL_POINTER; *directory = NULL; - /* XXX Handle read-only databases properly */ - if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY) - return NOTMUCH_STATUS_READ_ONLY_DATABASE; - try { - *directory = _notmuch_directory_create (notmuch, path, NOTMUCH_FIND_CREATE, &status); + *directory = _notmuch_directory_create (notmuch, path, + NOTMUCH_FIND_LOOKUP, &status); } catch (const Xapian::Error &error) { fprintf (stderr, "A Xapian exception occurred getting directory: %s.\n", error.get_msg().c_str()); diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index 34f7ac7..bfb4111 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -148,6 +148,9 @@ typedef enum _notmuch_private_status { /* Flags shared by various lookup functions. */ typedef enum _notmuch_find_flags { + /* Lookup without creating any documents. This is the default + * behavior. */ + NOTMUCH_FIND_LOOKUP = 0, /* If set, create the necessary document (or documents) if they * are missing. Requires a read/write database. */ NOTMUCH_FIND_CREATE = 1<<0, diff --git a/lib/notmuch.h b/lib/notmuch.h index bbb17e4..3633bed 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -300,10 +300,8 @@ notmuch_database_end_atomic (notmuch_database_t *notmuch); * (see notmuch_database_get_path), or else should be an absolute path * with initial components that match the path of 'database'. * - * Note: Currently this will create the directory object if it doesn't - * exist. In the future, when a directory object does not exist this - * will return NOTMUCH_STATUS_SUCCESS and set *directory to NULL. - * Callers should be prepared for this. + * If this directory object does not exist in the database, this + * returns NOTMUCH_STATUS_SUCCESS and sets *directory to NULL. * * Return value: * @@ -313,10 +311,6 @@ notmuch_database_end_atomic (notmuch_database_t *notmuch); * * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred; * directory not retrieved. - * - * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only - * mode so the directory cannot be created (this case will be - * removed in the future). */ notmuch_status_t notmuch_database_get_directory (notmuch_database_t *database, -- 1.7.10