[PATCH 10/11] cli/insert: require succesful message indexing for success status
authorJani Nikula <jani@nikula.org>
Mon, 22 Sep 2014 09:55:01 +0000 (11:55 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:04:39 +0000 (10:04 -0800)
e2/4234198971e6f518e2ab48bd31ffc1d1ae43d0 [new file with mode: 0644]

diff --git a/e2/4234198971e6f518e2ab48bd31ffc1d1ae43d0 b/e2/4234198971e6f518e2ab48bd31ffc1d1ae43d0
new file mode 100644 (file)
index 0000000..092e949
--- /dev/null
@@ -0,0 +1,146 @@
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 92B9F431FC0\r
+       for <notmuch@notmuchmail.org>; Mon, 22 Sep 2014 02:55:46 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id twU0Ql7jBTp9 for <notmuch@notmuchmail.org>;\r
+       Mon, 22 Sep 2014 02:55:40 -0700 (PDT)\r
+Received: from mail-wi0-f170.google.com (mail-wi0-f170.google.com\r
+       [209.85.212.170]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 7E704431FDA\r
+       for <notmuch@notmuchmail.org>; Mon, 22 Sep 2014 02:55:02 -0700 (PDT)\r
+Received: by mail-wi0-f170.google.com with SMTP id fb4so2489708wid.1\r
+       for <notmuch@notmuchmail.org>; Mon, 22 Sep 2014 02:55:01 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=1e100.net; s=20130820;\r
+       h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
+       :references:in-reply-to:references;\r
+       bh=n5qzNbP0UoBxlIxPTFASBybVy4EgoUOqeh3ijN5ZfcM=;\r
+       b=B6W0nCstiMyb635HidESCTrlFbz6MSUynqUYmvphUYaxggFME0MBLu38nG5cnoT+Rv\r
+       oAU2nQOkA3eoP+xCbg23Dx3QThvyFVfBd4Wr+ToBz7s9bZRSOQf/usw/j443IHrQLKN1\r
+       PRH1tZUmRw0DvkWHrjNwOQuFCyamKs38n+aJcrpCpK2s7PsUNf1d6sEO8dxjhgJANduu\r
+       PP38WbNer/azLUEYMmof+NO6mbJO8EE1qYUT3121Ys4HpYU7z7Pda4vHAswWMyK29Eyk\r
+       RFmzp/zpE75xAHztHTXT5ugzvpzQPH0fHMF7XCqTUs11YWQZgb8Sh3FsrBT5Lx1FaUyZ\r
+       UaKA==\r
+X-Gm-Message-State:\r
+ ALoCoQlSQNtcG1Df7nOGLPisFLbPmBJGwPF8wAPPDrDh8jyZXu5YLWROx4bGFQDn3jfnP6gN5zql\r
+X-Received: by 10.194.78.41 with SMTP id y9mr19032742wjw.24.1411379701415;\r
+       Mon, 22 Sep 2014 02:55:01 -0700 (PDT)\r
+Received: from localhost ([2001:4b98:dc0:43:216:3eff:fe1b:25f3])\r
+       by mx.google.com with ESMTPSA id p1sm11721573wjy.22.2014.09.22.02.55.00\r
+       for <multiple recipients>\r
+       (version=TLSv1.1 cipher=RC4-SHA bits=128/128);\r
+       Mon, 22 Sep 2014 02:55:00 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 10/11] cli/insert: require succesful message indexing for\r
+       success status\r
+Date: Mon, 22 Sep 2014 11:55:01 +0200\r
+Message-Id:\r
+ <84d4706c8d556769aa3330bf6ca9cfe92fb6213e.1411379395.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.2.5\r
+In-Reply-To: <cover.1411379395.git.jani@nikula.org>\r
+References: <cover.1411379395.git.jani@nikula.org>\r
+In-Reply-To: <cover.1411379395.git.jani@nikula.org>\r
+References: <cover.1411379395.git.jani@nikula.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 22 Sep 2014 09:55:46 -0000\r
+\r
+Add --keep option to keep any remaining stuff in index or file. We\r
+could distinguish between failures to index and failures to apply tags\r
+or maildir sync, but for simplicity just have one.\r
+---\r
+ notmuch-insert.c    |   20 +++++++++++++++-----\r
+ test/T070-insert.sh |    2 +-\r
+ 2 files changed, 16 insertions(+), 6 deletions(-)\r
+\r
+diff --git a/notmuch-insert.c b/notmuch-insert.c\r
+index 80f52d4..f27b9cb 100644\r
+--- a/notmuch-insert.c\r
++++ b/notmuch-insert.c\r
+@@ -433,6 +433,7 @@ DONE:\r
+ int\r
+ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
+ {\r
++    notmuch_status_t status;\r
+     notmuch_database_t *notmuch;\r
+     struct sigaction action;\r
+     const char *db_path;\r
+@@ -442,6 +443,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
+     char *query_string = NULL;\r
+     const char *folder = NULL;\r
+     notmuch_bool_t create_folder = FALSE;\r
++    notmuch_bool_t keep = FALSE;\r
+     notmuch_bool_t synchronize_flags;\r
+     const char *maildir;\r
+     char *newpath;\r
+@@ -451,6 +453,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
+     notmuch_opt_desc_t options[] = {\r
+       { NOTMUCH_OPT_STRING, &folder, "folder", 0, 0 },\r
+       { NOTMUCH_OPT_BOOLEAN, &create_folder, "create-folder", 0, 0 },\r
++      { NOTMUCH_OPT_BOOLEAN, &keep, "keep", 0, 0 },\r
+       { NOTMUCH_OPT_END, 0, 0, 0, 0 }\r
+     };\r
\r
+@@ -525,11 +528,18 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
+       return EXIT_FAILURE;\r
+     }\r
\r
+-    /* Add the message to the index.\r
+-     * Even if adding the message to the notmuch database fails,\r
+-     * the message is on disk and we consider the delivery completed. */\r
+-    add_file (notmuch, newpath, tag_ops, synchronize_flags, TRUE);\r
++    /* Index the message. */\r
++    status = add_file (notmuch, newpath, tag_ops, synchronize_flags, keep);\r
++    if (status) {\r
++      if (keep) {\r
++          status = NOTMUCH_STATUS_SUCCESS;\r
++      } else {\r
++          /* If maildir flag sync failed, this might fail. */\r
++          unlink (newpath);\r
++      }\r
++    }\r
\r
+     notmuch_database_destroy (notmuch);\r
+-    return EXIT_SUCCESS;\r
++\r
++    return status ? EXIT_FAILURE : EXIT_SUCCESS;\r
+ }\r
+diff --git a/test/T070-insert.sh b/test/T070-insert.sh\r
+index ea9db07..aacc643 100755\r
+--- a/test/T070-insert.sh\r
++++ b/test/T070-insert.sh\r
+@@ -23,7 +23,7 @@ test_expect_code 1 "Insert zero-length file" \\r
\r
+ # This test is a proxy for other errors that may occur while trying to\r
+ # add a message to the notmuch database, e.g. database locked.\r
+-test_expect_code 0 "Insert non-message" \\r
++test_expect_code 1 "Insert non-message" \\r
+     "echo bad_message | notmuch insert"\r
\r
+ test_begin_subtest "Database empty so far"\r
+-- \r
+1.7.2.5\r
+\r