From: Jani Nikula Date: Mon, 22 Sep 2014 09:54:54 +0000 (+0200) Subject: [PATCH 03/11] cli/insert: move add_file_to_database to a better place X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a026161d7208e36ed3df09e1a23b490c8e541e13;p=notmuch-archives.git [PATCH 03/11] cli/insert: move add_file_to_database to a better place --- diff --git a/3c/cd3152c73236b84e3ec13972d0a53a10906c40 b/3c/cd3152c73236b84e3ec13972d0a53a10906c40 new file mode 100644 index 000000000..f2bcbcc8e --- /dev/null +++ b/3c/cd3152c73236b84e3ec13972d0a53a10906c40 @@ -0,0 +1,189 @@ +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 2AC4E431FDC + for ; Mon, 22 Sep 2014 02:55:05 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +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 4XMGJ5MzuX95 for ; + Mon, 22 Sep 2014 02:55:00 -0700 (PDT) +Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com + [209.85.212.171]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id A1318431FC0 + for ; Mon, 22 Sep 2014 02:54:52 -0700 (PDT) +Received: by mail-wi0-f171.google.com with SMTP id ho1so2552447wib.16 + for ; Mon, 22 Sep 2014 02:54:51 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to + :references:in-reply-to:references; + bh=fz9Hb+n6ma8fvn9E4RKit/ex3/v5mYWMnz/lwYDVULc=; + b=KLwX3OTt1hk+6hckGH86s33f+2NBUF7pCMcbqGNOzKK3tcvs2eHz0vczy6V9Pfc432 + 2Vty8n0FVz/4OGLZpLaFX0lIvqQ6j7sceT92qA1z0r1MkJW8z12XlOtowLejMooXDV/D + Gg45H9i0whsSJZ492XPp51PRBWiWj2oFjATjk/JAfNX4qxSKn7b8d9nLR6ca9y/Lg1pV + MBfpMwCTv8yT8QCWPZrQWavcb4pro7zW7zcDoA3QHB6oqnYdlXBS/U+Sw4Y+bM9ULByB + YkvYxohgQJOFRq8l7sQCuoQ5q04i0vyyl3FkWeyiSJ2NG2gAkcM8lNWtGWZiW9aCL0e4 + UXYA== +X-Gm-Message-State: + ALoCoQktWBsZoP6/X4gstO10FzQEehfC43iL3m0Fgxf72Jxi0I2szN5wbNDNF5PUTkpDhXaxXk6w +X-Received: by 10.194.202.231 with SMTP id kl7mr1046611wjc.134.1411379691594; + Mon, 22 Sep 2014 02:54:51 -0700 (PDT) +Received: from localhost ([2001:4b98:dc0:43:216:3eff:fe1b:25f3]) + by mx.google.com with ESMTPSA id + ny6sm11466422wic.22.2014.09.22.02.54.50 for + (version=TLSv1.1 cipher=RC4-SHA bits=128/128); + Mon, 22 Sep 2014 02:54:51 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH 03/11] cli/insert: move add_file_to_database to a better place +Date: Mon, 22 Sep 2014 11:54:54 +0200 +Message-Id: + <84d2fc033adbb5cbddb49a937b71ba1f74a701c0.1411379395.git.jani@nikula.org> +X-Mailer: git-send-email 1.7.2.5 +In-Reply-To: +References: +In-Reply-To: +References: +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: Mon, 22 Sep 2014 09:55:05 -0000 + +Move add_file_to_database around to keep the filesystem related +functions grouped together, improving readability. No functional +changes. +--- + notmuch-insert.c | 92 +++++++++++++++++++++++++++--------------------------- + 1 files changed, 46 insertions(+), 46 deletions(-) + +diff --git a/notmuch-insert.c b/notmuch-insert.c +index 770275b..ccb091a 100644 +--- a/notmuch-insert.c ++++ b/notmuch-insert.c +@@ -294,52 +294,6 @@ copy_stdin (int fdin, int fdout) + return (!interrupted && !empty); + } + +-/* Add the specified message file to the notmuch database, applying tags. +- * The file is renamed to encode notmuch tags as maildir flags. */ +-static void +-add_file_to_database (notmuch_database_t *notmuch, const char *path, +- tag_op_list_t *tag_ops, notmuch_bool_t synchronize_flags) +-{ +- notmuch_message_t *message; +- notmuch_status_t status; +- +- status = notmuch_database_add_message (notmuch, path, &message); +- switch (status) { +- case NOTMUCH_STATUS_SUCCESS: +- case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: +- break; +- default: +- case NOTMUCH_STATUS_FILE_NOT_EMAIL: +- case NOTMUCH_STATUS_READ_ONLY_DATABASE: +- case NOTMUCH_STATUS_XAPIAN_EXCEPTION: +- case NOTMUCH_STATUS_OUT_OF_MEMORY: +- case NOTMUCH_STATUS_FILE_ERROR: +- case NOTMUCH_STATUS_NULL_POINTER: +- case NOTMUCH_STATUS_TAG_TOO_LONG: +- case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW: +- case NOTMUCH_STATUS_UNBALANCED_ATOMIC: +- case NOTMUCH_STATUS_LAST_STATUS: +- fprintf (stderr, "Error: failed to add `%s' to notmuch database: %s\n", +- path, notmuch_status_to_string (status)); +- return; +- } +- +- if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) { +- /* Don't change tags of an existing message. */ +- if (synchronize_flags) { +- status = notmuch_message_tags_to_maildir_flags (message); +- if (status != NOTMUCH_STATUS_SUCCESS) +- fprintf (stderr, "Error: failed to sync tags to maildir flags\n"); +- } +- } else { +- tag_op_flag_t flags = synchronize_flags ? TAG_FLAG_MAILDIR_SYNC : 0; +- +- tag_op_list_apply (message, tag_ops, flags); +- } +- +- notmuch_message_destroy (message); +-} +- + static notmuch_bool_t + write_message (void *ctx, int fdin, const char *dir, char **newpath) + { +@@ -389,6 +343,52 @@ write_message (void *ctx, int fdin, const char *dir, char **newpath) + return FALSE; + } + ++/* Add the specified message file to the notmuch database, applying tags. ++ * The file is renamed to encode notmuch tags as maildir flags. */ ++static void ++add_file_to_database (notmuch_database_t *notmuch, const char *path, ++ tag_op_list_t *tag_ops, notmuch_bool_t synchronize_flags) ++{ ++ notmuch_message_t *message; ++ notmuch_status_t status; ++ ++ status = notmuch_database_add_message (notmuch, path, &message); ++ switch (status) { ++ case NOTMUCH_STATUS_SUCCESS: ++ case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: ++ break; ++ default: ++ case NOTMUCH_STATUS_FILE_NOT_EMAIL: ++ case NOTMUCH_STATUS_READ_ONLY_DATABASE: ++ case NOTMUCH_STATUS_XAPIAN_EXCEPTION: ++ case NOTMUCH_STATUS_OUT_OF_MEMORY: ++ case NOTMUCH_STATUS_FILE_ERROR: ++ case NOTMUCH_STATUS_NULL_POINTER: ++ case NOTMUCH_STATUS_TAG_TOO_LONG: ++ case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW: ++ case NOTMUCH_STATUS_UNBALANCED_ATOMIC: ++ case NOTMUCH_STATUS_LAST_STATUS: ++ fprintf (stderr, "Error: failed to add `%s' to notmuch database: %s\n", ++ path, notmuch_status_to_string (status)); ++ return; ++ } ++ ++ if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) { ++ /* Don't change tags of an existing message. */ ++ if (synchronize_flags) { ++ status = notmuch_message_tags_to_maildir_flags (message); ++ if (status != NOTMUCH_STATUS_SUCCESS) ++ fprintf (stderr, "Error: failed to sync tags to maildir flags\n"); ++ } ++ } else { ++ tag_op_flag_t flags = synchronize_flags ? TAG_FLAG_MAILDIR_SYNC : 0; ++ ++ tag_op_list_apply (message, tag_ops, flags); ++ } ++ ++ notmuch_message_destroy (message); ++} ++ + int + notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) + { +-- +1.7.2.5 +