From: Jani Nikula Date: Mon, 22 Sep 2014 09:55:01 +0000 (+0200) Subject: [PATCH 10/11] cli/insert: require succesful message indexing for success status X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1f42ad61cbd2ca03aa2333b9b0a6d3bf56906f02;p=notmuch-archives.git [PATCH 10/11] cli/insert: require succesful message indexing for success status --- diff --git a/e2/4234198971e6f518e2ab48bd31ffc1d1ae43d0 b/e2/4234198971e6f518e2ab48bd31ffc1d1ae43d0 new file mode 100644 index 000000000..092e949fa --- /dev/null +++ b/e2/4234198971e6f518e2ab48bd31ffc1d1ae43d0 @@ -0,0 +1,146 @@ +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 92B9F431FC0 + for ; Mon, 22 Sep 2014 02:55:46 -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 twU0Ql7jBTp9 for ; + Mon, 22 Sep 2014 02:55:40 -0700 (PDT) +Received: from mail-wi0-f170.google.com (mail-wi0-f170.google.com + [209.85.212.170]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 7E704431FDA + for ; Mon, 22 Sep 2014 02:55:02 -0700 (PDT) +Received: by mail-wi0-f170.google.com with SMTP id fb4so2489708wid.1 + for ; Mon, 22 Sep 2014 02:55:01 -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=n5qzNbP0UoBxlIxPTFASBybVy4EgoUOqeh3ijN5ZfcM=; + b=B6W0nCstiMyb635HidESCTrlFbz6MSUynqUYmvphUYaxggFME0MBLu38nG5cnoT+Rv + oAU2nQOkA3eoP+xCbg23Dx3QThvyFVfBd4Wr+ToBz7s9bZRSOQf/usw/j443IHrQLKN1 + PRH1tZUmRw0DvkWHrjNwOQuFCyamKs38n+aJcrpCpK2s7PsUNf1d6sEO8dxjhgJANduu + PP38WbNer/azLUEYMmof+NO6mbJO8EE1qYUT3121Ys4HpYU7z7Pda4vHAswWMyK29Eyk + RFmzp/zpE75xAHztHTXT5ugzvpzQPH0fHMF7XCqTUs11YWQZgb8Sh3FsrBT5Lx1FaUyZ + UaKA== +X-Gm-Message-State: + ALoCoQlSQNtcG1Df7nOGLPisFLbPmBJGwPF8wAPPDrDh8jyZXu5YLWROx4bGFQDn3jfnP6gN5zql +X-Received: by 10.194.78.41 with SMTP id y9mr19032742wjw.24.1411379701415; + Mon, 22 Sep 2014 02:55:01 -0700 (PDT) +Received: from localhost ([2001:4b98:dc0:43:216:3eff:fe1b:25f3]) + by mx.google.com with ESMTPSA id p1sm11721573wjy.22.2014.09.22.02.55.00 + for + (version=TLSv1.1 cipher=RC4-SHA bits=128/128); + Mon, 22 Sep 2014 02:55:00 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH 10/11] cli/insert: require succesful message indexing for + success status +Date: Mon, 22 Sep 2014 11:55:01 +0200 +Message-Id: + <84d4706c8d556769aa3330bf6ca9cfe92fb6213e.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:46 -0000 + +Add --keep option to keep any remaining stuff in index or file. We +could distinguish between failures to index and failures to apply tags +or maildir sync, but for simplicity just have one. +--- + notmuch-insert.c | 20 +++++++++++++++----- + test/T070-insert.sh | 2 +- + 2 files changed, 16 insertions(+), 6 deletions(-) + +diff --git a/notmuch-insert.c b/notmuch-insert.c +index 80f52d4..f27b9cb 100644 +--- a/notmuch-insert.c ++++ b/notmuch-insert.c +@@ -433,6 +433,7 @@ DONE: + int + notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) + { ++ notmuch_status_t status; + notmuch_database_t *notmuch; + struct sigaction action; + const char *db_path; +@@ -442,6 +443,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) + char *query_string = NULL; + const char *folder = NULL; + notmuch_bool_t create_folder = FALSE; ++ notmuch_bool_t keep = FALSE; + notmuch_bool_t synchronize_flags; + const char *maildir; + char *newpath; +@@ -451,6 +453,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) + notmuch_opt_desc_t options[] = { + { NOTMUCH_OPT_STRING, &folder, "folder", 0, 0 }, + { NOTMUCH_OPT_BOOLEAN, &create_folder, "create-folder", 0, 0 }, ++ { NOTMUCH_OPT_BOOLEAN, &keep, "keep", 0, 0 }, + { NOTMUCH_OPT_END, 0, 0, 0, 0 } + }; + +@@ -525,11 +528,18 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) + return EXIT_FAILURE; + } + +- /* Add the message to the index. +- * Even if adding the message to the notmuch database fails, +- * the message is on disk and we consider the delivery completed. */ +- add_file (notmuch, newpath, tag_ops, synchronize_flags, TRUE); ++ /* Index the message. */ ++ status = add_file (notmuch, newpath, tag_ops, synchronize_flags, keep); ++ if (status) { ++ if (keep) { ++ status = NOTMUCH_STATUS_SUCCESS; ++ } else { ++ /* If maildir flag sync failed, this might fail. */ ++ unlink (newpath); ++ } ++ } + + notmuch_database_destroy (notmuch); +- return EXIT_SUCCESS; ++ ++ return status ? EXIT_FAILURE : EXIT_SUCCESS; + } +diff --git a/test/T070-insert.sh b/test/T070-insert.sh +index ea9db07..aacc643 100755 +--- a/test/T070-insert.sh ++++ b/test/T070-insert.sh +@@ -23,7 +23,7 @@ test_expect_code 1 "Insert zero-length file" \ + + # This test is a proxy for other errors that may occur while trying to + # add a message to the notmuch database, e.g. database locked. +-test_expect_code 0 "Insert non-message" \ ++test_expect_code 1 "Insert non-message" \ + "echo bad_message | notmuch insert" + + test_begin_subtest "Database empty so far" +-- +1.7.2.5 +