From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 7DAF0429E26 for ; Thu, 17 May 2012 21:13:54 -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 Q5RtEdegnuzs for ; Thu, 17 May 2012 21:13:53 -0700 (PDT) Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU [18.7.68.34]) by olra.theworths.org (Postfix) with ESMTP id DDBED431FC2 for ; Thu, 17 May 2012 21:13:52 -0700 (PDT) X-AuditID: 12074422-b7fd66d0000008f9-89-4fb5cc801be8 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP id 83.DF.02297.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-2.mit.edu (8.13.8/8.9.2) with ESMTP id q4I4DpwB021451; 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 q4I4DoVJ026786 (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-0000z3-3l; Fri, 18 May 2012 00:13:50 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 3/9] lib: Perform the same transformation to _notmuch_database_filename_to_direntry Date: Fri, 18 May 2012 00:13:36 -0400 Message-Id: <1337314423-3702-4-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+NgFtrAIsWRmVeSWpSXmKPExsUixG6nottwZqu/wcvlEhbXb85kdmD0eLbq FnMAYxSXTUpqTmZZapG+XQJXxpXTdQVTZSqm3bBpYDwo1sXIySEhYCKxef8WRghbTOLCvfVs XYxcHEIC+xglrr/awAjhbGCUmND6iAnCuc8ksWP7dhYIZxajxI+Xh1lB+tkENCS27V8ONktE QFpi593ZQHEODmYBNYk/XSogYWGBFIkjPS1g5SwCqhLXt+1gArF5BewlfrdeZoI4Q17i6f0+ NpBWTgEHiWnHo0HCQkAl/y40s0xg5F/AyLCKUTYlt0o3NzEzpzg1Wbc4OTEvL7VI11QvN7NE LzWldBMjOGBclHYw/jyodIhRgINRiYd3x5yt/kKsiWXFlbmHGCU5mJREeb+fBArxJeWnVGYk FmfEF5XmpBYfYpTgYFYS4ZXtBsrxpiRWVqUW5cOkpDlYlMR51bXe+QkJpCeWpGanphakFsFk ZTg4lCR4LU4DNQoWpaanVqRl5pQgpJk4OEGG8wANzwSp4S0uSMwtzkyHyJ9iVJQS5y0DSQiA JDJK8+B6YRH9ilEc6BVh3lCQKh5gMoDrfgU0mAlocFnuJpDBJYkIKakGRov0Vt+yvY/lexeH NtZosjbc+Z9korJn152sjX05q/QMGXedXP3Wc8Wirh8qoWkW7cXzzXQlBI2Noy02MtfquBvy JrAf2FRy85bnpZWGr+uOcDntdPt8XW1Bsf30qJSztit8OrZcPCa+MfT9r4dC5bfYdN79y9ad 36MRJaDLxVXLepPNdxeXEktxRqKhFnNRcSIA5wWB0MMCAAA= 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:54 -0000 Now _notmuch_database_filename_to_direntry takes a flags argument and can indicate if the necessary directory documents do not exist. Again, callers have been updated, but retain their original behavior. --- lib/database.cc | 17 +++++++++++------ lib/message.cc | 9 ++++----- lib/notmuch-private.h | 1 + 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index 716982d..b4c76b4 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -1248,13 +1248,16 @@ _notmuch_database_get_directory_path (void *ctx, * database path), return a new string (with 'ctx' as the talloc * owner) suitable for use as a direntry term value. * - * The necessary directory documents will be created in the database - * as needed. + * If (flags & NOTMUCH_FIND_CREATE), the necessary directory documents + * will be created in the database as needed. Otherwise, if the + * necessary directory documents do not exist, this sets + * *direntry to NULL and returns NOTMUCH_STATUS_SUCCESS. */ notmuch_status_t _notmuch_database_filename_to_direntry (void *ctx, notmuch_database_t *notmuch, const char *filename, + notmuch_find_flags_t flags, char **direntry) { const char *relative, *directory, *basename; @@ -1268,10 +1271,12 @@ _notmuch_database_filename_to_direntry (void *ctx, if (status) return status; - status = _notmuch_database_find_directory_id (notmuch, directory, NOTMUCH_FIND_CREATE, + status = _notmuch_database_find_directory_id (notmuch, directory, flags, &directory_id); - if (status) + if (status || directory_id == (unsigned int)-1) { + *direntry = NULL; return status; + } *direntry = talloc_asprintf (ctx, "%u:%s", directory_id, basename); @@ -1892,8 +1897,8 @@ notmuch_database_find_message_by_filename (notmuch_database_t *notmuch, local = talloc_new (notmuch); try { - status = _notmuch_database_filename_to_direntry (local, notmuch, - filename, &direntry); + status = _notmuch_database_filename_to_direntry ( + local, notmuch, filename, NOTMUCH_FIND_CREATE, &direntry); if (status) goto DONE; diff --git a/lib/message.cc b/lib/message.cc index 0075425..8d552f1 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -495,9 +495,8 @@ _notmuch_message_add_filename (notmuch_message_t *message, if (status) return status; - status = _notmuch_database_filename_to_direntry (local, - message->notmuch, - filename, &direntry); + status = _notmuch_database_filename_to_direntry ( + local, message->notmuch, filename, NOTMUCH_FIND_CREATE, &direntry); if (status) return status; @@ -541,8 +540,8 @@ _notmuch_message_remove_filename (notmuch_message_t *message, notmuch_status_t status; Xapian::TermIterator i, last; - status = _notmuch_database_filename_to_direntry (local, message->notmuch, - filename, &direntry); + status = _notmuch_database_filename_to_direntry ( + local, message->notmuch, filename, NOTMUCH_FIND_CREATE, &direntry); if (status) return status; diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index a36549d..34f7ac7 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -207,6 +207,7 @@ notmuch_status_t _notmuch_database_filename_to_direntry (void *ctx, notmuch_database_t *notmuch, const char *filename, + notmuch_find_flags_t flags, char **direntry); /* directory.cc */ -- 1.7.10