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 E2D6B431FC2 for ; Thu, 17 May 2012 21:13:55 -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 iWrpJCR5tF2x for ; Thu, 17 May 2012 21:13:54 -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 EE18D431FD5 for ; Thu, 17 May 2012 21:13:52 -0700 (PDT) X-AuditID: 1209190f-b7f4f6d00000092b-3d-4fb5cc8049b9 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP id E7.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-2.mit.edu (8.13.8/8.9.2) with ESMTP id q4I4Dpdn021450; 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 q4I4DoEY026783 (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 1SVEZZ-0000z0-Uw; Fri, 18 May 2012 00:13:50 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 2/9] lib: Perform the same transformation to _notmuch_database_find_directory_id Date: Fri, 18 May 2012 00:13:35 -0400 Message-Id: <1337314423-3702-3-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+NgFtrIIsWRmVeSWpSXmKPExsUixG6nottwZqu/wYsPEhbXb85kdmD0eLbq FnMAYxSXTUpqTmZZapG+XQJXxqVLdxgLJklUbL/2gbWBcYtwFyMnh4SAicT7PT3MELaYxIV7 69lAbCGBfYwSE19qdzFyAdkbGCVuXlrNAuHcZ5LoPf6XGcKZxSjx8cB1RpAWNgENiW37l4PZ IgLSEjvvzmbtYuTgYBZQk/jTpQISFhZIkDi7dDkriM0ioCrx/M8OsM28AvYS329OZIW4Ql7i 6f0+NpBWTgEHiWnHoyEOspf4d6GZZQIj/wJGhlWMsim5Vbq5iZk5xanJusXJiXl5qUW6Jnq5 mSV6qSmlmxhBIcMpyb+D8dtBpUOMAhyMSjy8O+Zs9RdiTSwrrsw9xCjJwaQkyvv9JFCILyk/ pTIjsTgjvqg0J7X4EKMEB7OSCK9sN1CONyWxsiq1KB8mJc3BoiTOq6b1zk9IID2xJDU7NbUg tQgmK8PBoSTBa3EaqFGwKDU9tSItM6cEIc3EwQkynAdouBZIDW9xQWJucWY6RP4Uo6KUOK8N SEIAJJFRmgfXC4vpV4ziQK8I84aCVPEA0wFc9yugwUxAg8tyN4EMLklESEk1MIa91Jpfs43t dmvQg18tvHNFA0z4Wz6vlk45NGnNqoDNoaGaTuZpQavd9sgwXuYQOfhneqv0y9bZ1x7LvPNr mmqS8M3kdt2Zp/rbG/5ZTj11MdN3n+H9i647hWpyhXWXNxTsEPa+2x30Zus9pXbTWcX1j973 23ld85Lmzb7atuNEZPNyy/vzRJRYijMSDbWYi4oTAUeKw4bEAgAA 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:56 -0000 Now _notmuch_database_find_directory_id takes a flags argument, which it passes through to _notmuch_directory_create and can indicate if the directory does not exist. Again, callers have been updated, but retain their original behavior. --- lib/database.cc | 14 +++++++++++--- lib/directory.cc | 8 +++++++- lib/notmuch-private.h | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index df996a9..716982d 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -1197,9 +1197,17 @@ _notmuch_database_split_path (void *ctx, return NOTMUCH_STATUS_SUCCESS; } +/* Find the document ID of the specified directory. + * + * If (flags & NOTMUCH_FIND_CREATE), a new directory document will be + * created if one does not exist for 'path'. Otherwise, if the + * directory document does not exist, this sets *directory_id to + * ((unsigned int)-1) and returns NOTMUCH_STATUS_SUCCESS. + */ notmuch_status_t _notmuch_database_find_directory_id (notmuch_database_t *notmuch, const char *path, + notmuch_find_flags_t flags, unsigned int *directory_id) { notmuch_directory_t *directory; @@ -1210,8 +1218,8 @@ _notmuch_database_find_directory_id (notmuch_database_t *notmuch, return NOTMUCH_STATUS_SUCCESS; } - directory = _notmuch_directory_create (notmuch, path, NOTMUCH_FIND_CREATE, &status); - if (status) { + directory = _notmuch_directory_create (notmuch, path, flags, &status); + if (status || !directory) { *directory_id = -1; return status; } @@ -1260,7 +1268,7 @@ _notmuch_database_filename_to_direntry (void *ctx, if (status) return status; - status = _notmuch_database_find_directory_id (notmuch, directory, + status = _notmuch_database_find_directory_id (notmuch, directory, NOTMUCH_FIND_CREATE, &directory_id); if (status) return status; diff --git a/lib/directory.cc b/lib/directory.cc index 83bb19b..6a3ffed 100644 --- a/lib/directory.cc +++ b/lib/directory.cc @@ -153,7 +153,13 @@ _notmuch_directory_create (notmuch_database_t *notmuch, _notmuch_database_split_path (local, path, &parent, &basename); - _notmuch_database_find_directory_id (notmuch, parent, &parent_id); + *status_ret = _notmuch_database_find_directory_id ( + notmuch, parent, NOTMUCH_FIND_CREATE, &parent_id); + if (*status_ret) { + notmuch_directory_destroy (directory); + directory = NULL; + goto DONE; + } if (basename) { term = talloc_asprintf (local, "%s%u:%s", diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index 538274f..a36549d 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -195,6 +195,7 @@ _notmuch_database_find_unique_doc_id (notmuch_database_t *notmuch, notmuch_status_t _notmuch_database_find_directory_id (notmuch_database_t *database, const char *path, + notmuch_find_flags_t flags, unsigned int *directory_id); const char * -- 1.7.10