From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 09FBF6DE1E3D for ; Sat, 18 Feb 2017 06:46:58 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.005 X-Spam-Level: X-Spam-Status: No, score=-0.005 tagged_above=-999 required=5 tests=[AWL=0.006, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3NnaUpxNWRlA for ; Sat, 18 Feb 2017 06:46:57 -0800 (PST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id CE8BB6DE1E40 for ; Sat, 18 Feb 2017 06:46:42 -0800 (PST) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1cf6Gz-0004Zf-J0; Sat, 18 Feb 2017 09:46:05 -0500 Received: (nullmailer pid 23036 invoked by uid 1000); Sat, 18 Feb 2017 14:46:33 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 8/8] lib: add status return to notmuch_message_get_flag Date: Sat, 18 Feb 2017 10:45:51 -0400 Message-Id: <20170218144551.22925-9-david@tethera.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170218144551.22925-1-david@tethera.net> References: <20170218144551.22925-1-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.22 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: Sat, 18 Feb 2017 14:46:58 -0000 This is needed to propagate errors from notmuch_message_ensure_metadata. We make all the changes needed to keep the code compiling in atomically in this commit. --- lib/database.cc | 9 ++++++--- lib/message.cc | 21 ++++++++++++++++----- lib/notmuch.h | 10 ++++++++-- lib/thread.cc | 16 +++++++++++++--- notmuch-client.h | 15 +++++++++++++++ notmuch-search.c | 2 +- notmuch-show.c | 12 ++++++------ 7 files changed, 65 insertions(+), 20 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index 2d19f20c..b60d1f23 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -2519,9 +2519,12 @@ notmuch_database_add_message (notmuch_database_t *notmuch, * message? We have to be slightly careful: if this is a * blank message, it's not safe to call * notmuch_message_get_flag yet. */ - if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND || - (is_ghost = notmuch_message_get_flag ( - message, NOTMUCH_MESSAGE_FLAG_GHOST))) { + if (private_status != NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) { + ret = notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_GHOST, &is_ghost); + if (ret) + goto DONE; + } + if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND || is_ghost) { _notmuch_message_add_term (message, "type", "mail"); if (is_ghost) /* Convert ghost message to a regular message */ diff --git a/lib/message.cc b/lib/message.cc index fee8fc24..a319fde7 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -946,15 +946,26 @@ notmuch_message_get_filenames (notmuch_message_t *message) return _notmuch_filenames_create (message, message->filename_list); } -notmuch_bool_t +notmuch_status_t notmuch_message_get_flag (notmuch_message_t *message, - notmuch_message_flag_t flag) + notmuch_message_flag_t flag, + notmuch_bool_t *value) { + notmuch_private_status_t private_status; + + if (value == NULL) + return NOTMUCH_STATUS_NULL_POINTER; + if (flag == NOTMUCH_MESSAGE_FLAG_GHOST && - ! NOTMUCH_TEST_BIT (message->lazy_flags, flag)) - _notmuch_message_ensure_metadata (message); + ! NOTMUCH_TEST_BIT (message->lazy_flags, flag)) { + private_status = _notmuch_message_ensure_metadata (message); + if (private_status) + return COERCE_STATUS (private_status, + "Unhandled error reading message metadata"); + } - return NOTMUCH_TEST_BIT (message->flags, flag); + *value = NOTMUCH_TEST_BIT (message->flags, flag); + return NOTMUCH_STATUS_SUCCESS; } void diff --git a/lib/notmuch.h b/lib/notmuch.h index 5fd85105..ac588922 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -1379,10 +1379,16 @@ typedef enum _notmuch_message_flag { /** * Get a value of a flag for the email corresponding to 'message'. + * @returns + * - NOTMUCH_STATUS_XAPIAN_EXCEPTION: an error occured reading message metadata from disk + * - NOTMUCH_STATUS_NULL_POINTER: Neither *key* nor *value* may be NULL. + * - NOTMUCH_STATUS_SUCCESS: No error occured. + * @since libnotmuch 5 (notmuch 0.24) */ -notmuch_bool_t +notmuch_status_t notmuch_message_get_flag (notmuch_message_t *message, - notmuch_message_flag_t flag); + notmuch_message_flag_t flag, + notmuch_bool_t *value); /** * Set a value of a flag for the email corresponding to 'message'. diff --git a/lib/thread.cc b/lib/thread.cc index 84ee5298..56c9ea81 100644 --- a/lib/thread.cc +++ b/lib/thread.cc @@ -346,13 +346,15 @@ _thread_set_subject_from_message (notmuch_thread_t *thread, * search specification. The 'sort' parameter controls whether the * oldest or newest matching subject is applied to the thread as a * whole. */ -static void +static notmuch_status_t _thread_add_matched_message (notmuch_thread_t *thread, notmuch_message_t *message, notmuch_sort_t sort) { time_t date; notmuch_message_t *hashed_message; + notmuch_status_t status; + notmuch_bool_t is_excluded; date = notmuch_message_get_date (message); @@ -369,7 +371,11 @@ _thread_add_matched_message (notmuch_thread_t *thread, _thread_set_subject_from_message (thread, message); } - if (!notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED)) + status = notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, &is_excluded); + if (status) + return status; + + if (! is_excluded) thread->matched_messages++; if (g_hash_table_lookup_extended (thread->message_hash, @@ -380,6 +386,7 @@ _thread_add_matched_message (notmuch_thread_t *thread, } _thread_add_matched_author (thread, _notmuch_message_get_author (hashed_message)); + return NOTMUCH_STATUS_SUCCESS; } static void @@ -524,7 +531,10 @@ _notmuch_thread_create (void *ctx, if ( _notmuch_doc_id_set_contains (match_set, doc_id)) { _notmuch_doc_id_set_remove (match_set, doc_id); - _thread_add_matched_message (thread, message, sort); + if (_thread_add_matched_message (thread, message, sort)) { + thread = NULL; + goto DONE; + } } _notmuch_message_close (message); diff --git a/notmuch-client.h b/notmuch-client.h index d026e600..108b892b 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -492,6 +492,21 @@ print_status_database (const char *loc, int status_to_exit (notmuch_status_t status); +inline notmuch_bool_t +wrap_message_get_flag (notmuch_message_t *message, + notmuch_message_flag_t flag) { + notmuch_bool_t value; + notmuch_status_t status; + + status = print_status_database ("notmuch_message_get_flag", + notmuch_message_get_database (message), + notmuch_message_get_flag (message, flag, &value)); + if (status) + exit (status_to_exit (status)); + + return value; +} + #include "command-line-arguments.h" extern char *notmuch_requested_db_uuid; diff --git a/notmuch-search.c b/notmuch-search.c index 8c65d5ad..899eb09c 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -91,7 +91,7 @@ get_thread_query (notmuch_thread_t *thread, notmuch_message_t *message = notmuch_messages_get (messages); const char *mid = notmuch_message_get_message_id (message); /* Determine which query buffer to extend */ - char **buf = notmuch_message_get_flag ( + char **buf = wrap_message_get_flag ( message, NOTMUCH_MESSAGE_FLAG_MATCH) ? matched_out : unmatched_out; /* Add this message's id: query. Since "id" is an exclusive * prefix, it is implicitly 'or'd together, so we only need to diff --git a/notmuch-show.c b/notmuch-show.c index 22fa655a..398b084e 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -127,10 +127,10 @@ format_message_sprinter (sprinter_t *sp, notmuch_message_t *message) sp->string (sp, notmuch_message_get_message_id (message)); sp->map_key (sp, "match"); - sp->boolean (sp, notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH)); + sp->boolean (sp, wrap_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH)); sp->map_key (sp, "excluded"); - sp->boolean (sp, notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED)); + sp->boolean (sp, wrap_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED)); sp->map_key (sp, "filename"); sp->string (sp, notmuch_message_get_filename (message)); @@ -446,8 +446,8 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node, part_type, notmuch_message_get_message_id (message), indent, - notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) ? 1 : 0, - notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED) ? 1 : 0, + wrap_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) ? 1 : 0, + wrap_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED) ? 1 : 0, notmuch_message_get_filename (message)); } else { GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (meta); @@ -854,8 +854,8 @@ show_messages (void *ctx, message = notmuch_messages_get (messages); - match = notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH); - excluded = notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED); + match = wrap_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH); + excluded = wrap_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED); next_indent = indent; -- 2.11.0