From e64ff83b81cfacf310454134b5b2f451df7c6bac Mon Sep 17 00:00:00 2001 From: Peter Wang Date: Wed, 16 Apr 2014 22:59:22 +1000 Subject: [PATCH] [PATCH v2 07/10] cli: indicate insert failure mode in exit status --- d7/9706e65662b3413fae27b2a440dcdaf57a3c33 | 197 ++++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 d7/9706e65662b3413fae27b2a440dcdaf57a3c33 diff --git a/d7/9706e65662b3413fae27b2a440dcdaf57a3c33 b/d7/9706e65662b3413fae27b2a440dcdaf57a3c33 new file mode 100644 index 000000000..12ec517fa --- /dev/null +++ b/d7/9706e65662b3413fae27b2a440dcdaf57a3c33 @@ -0,0 +1,197 @@ +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 94A2D429E37 + for ; Wed, 16 Apr 2014 06:00:45 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.099 +X-Spam-Level: +X-Spam-Status: No, score=-0.099 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001] 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 XVBqombZ+Pgv for ; + Wed, 16 Apr 2014 06:00:40 -0700 (PDT) +Received: from mail-pd0-f169.google.com (mail-pd0-f169.google.com + [209.85.192.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 26E41431FAE + for ; Wed, 16 Apr 2014 06:00:13 -0700 (PDT) +Received: by mail-pd0-f169.google.com with SMTP id fp1so10780476pdb.0 + for ; Wed, 16 Apr 2014 06:00:12 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:cc:subject:date:message-id:in-reply-to:references; + bh=q8S0uIz/2t/fjxsh5T+/4TYA1Qp5sSDOxaIQGwwRb3Q=; + b=fUs0nYv7GbJklSB7pj5dVpsCvXra558t8RckqiFdGOnWNAeeaxxhOcLf4g53JUJ5ZJ + zozZqaod/BWvRQc7SEDzwbdfn1WrTQAHg8lCAHqc0P3K2BdKOw6tttt5xaMKhoZ3UNeX + xxEvWUV4C53jmJfZ5hydmpaSVSRKd6h/68WlcTpbs7BkWS94n4BYtVPxuole+x+7BUlW + YvMiHdcq/gL9NS/zS/TdE4R7i9svnRMYpKmSfpaWSNI7IosnKstZhuMYCd79cmm5uQNx + 8Er3jxV5N25yFzlJZApqQU7KHawPszIgX1bokL9mZv/oxPa6I7kkhdhj8p/B4dGUo1Gq + F+7g== +X-Received: by 10.66.102.72 with SMTP id fm8mr2695390pab.86.1397653212449; + Wed, 16 Apr 2014 06:00:12 -0700 (PDT) +Received: from localhost (215.42.233.220.static.exetel.com.au. + [220.233.42.215]) by mx.google.com with ESMTPSA id + nx12sm111066548pab.6.2014.04.16.06.00.10 for + (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Wed, 16 Apr 2014 06:00:11 -0700 (PDT) +From: Peter Wang +To: notmuch@notmuchmail.org +Subject: [PATCH v2 07/10] cli: indicate insert failure mode in exit status +Date: Wed, 16 Apr 2014 22:59:22 +1000 +Message-Id: <1397653165-15620-8-git-send-email-novalazy@gmail.com> +X-Mailer: git-send-email 1.8.4 +In-Reply-To: <1397653165-15620-1-git-send-email-novalazy@gmail.com> +References: <1397653165-15620-1-git-send-email-novalazy@gmail.com> +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: Wed, 16 Apr 2014 13:00:45 -0000 + +Make insert return a different exit code, 2, for failure to write the +message file to disk, and exit code 1 for other errors. +--- + notmuch-insert.c | 30 ++++++++++++++++++------------ + test/T070-insert.sh | 4 ++-- + 2 files changed, 20 insertions(+), 14 deletions(-) + +diff --git a/notmuch-insert.c b/notmuch-insert.c +index 7db4f73..29d82c9 100644 +--- a/notmuch-insert.c ++++ b/notmuch-insert.c +@@ -28,6 +28,12 @@ + #include + #include + ++enum { ++ INSERT_EXIT_SUCCESS = 0, ++ INSERT_EXIT_FAILURE = 1, ++ INSERT_EXIT_FAILED_WRITE = 2 ++}; ++ + static volatile sig_atomic_t interrupted; + + static void +@@ -408,7 +414,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) + + opt_index = parse_arguments (argc, argv, options, 1); + if (opt_index < 0) +- return EXIT_FAILURE; ++ return INSERT_EXIT_FAILURE; + + db_path = notmuch_config_get_database_path (config); + new_tags = notmuch_config_get_new_tags (config, &new_tags_length); +@@ -417,7 +423,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) + tag_ops = tag_op_list_create (config); + if (tag_ops == NULL) { + fprintf (stderr, "Out of memory.\n"); +- return EXIT_FAILURE; ++ return INSERT_EXIT_FAILURE; + } + for (i = 0; i < new_tags_length; i++) { + const char *error_msg; +@@ -426,20 +432,20 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) + if (error_msg) { + fprintf (stderr, "Error: tag '%s' in new.tags: %s\n", + new_tags[i], error_msg); +- return EXIT_FAILURE; ++ return INSERT_EXIT_FAILURE; + } + + if (tag_op_list_append (tag_ops, new_tags[i], FALSE)) +- return EXIT_FAILURE; ++ return INSERT_EXIT_FAILURE; + } + + if (parse_tag_command_line (config, argc - opt_index, argv + opt_index, + &query_string, tag_ops)) +- return EXIT_FAILURE; ++ return INSERT_EXIT_FAILURE; + + if (*query_string != '\0') { + fprintf (stderr, "Error: unexpected query string: %s\n", query_string); +- return EXIT_FAILURE; ++ return INSERT_EXIT_FAILURE; + } + + if (folder == NULL) { +@@ -447,17 +453,17 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) + } else { + if (! check_folder_name (folder)) { + fprintf (stderr, "Error: bad folder name: %s\n", folder); +- return EXIT_FAILURE; ++ return INSERT_EXIT_FAILURE; + } + maildir = talloc_asprintf (config, "%s/%s", db_path, folder); + if (! maildir) { + fprintf (stderr, "Out of memory\n"); +- return EXIT_FAILURE; ++ return INSERT_EXIT_FAILURE; + } + if (create_folder && ! maildir_create_folder (config, maildir)) { + fprintf (stderr, "Error: creating maildir %s: %s\n", + maildir, strerror (errno)); +- return EXIT_FAILURE; ++ return INSERT_EXIT_FAILURE; + } + } + +@@ -471,12 +477,12 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) + + if (notmuch_database_open (notmuch_config_get_database_path (config), + NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much)) +- return EXIT_FAILURE; ++ return INSERT_EXIT_FAILURE; + + /* Write the message to the Maildir new directory. */ + if (! write_message (config, STDIN_FILENO, maildir, &newpath)) { + notmuch_database_destroy (notmuch); +- return EXIT_FAILURE; ++ return INSERT_EXIT_FAILED_WRITE; + } + + /* Add the message to the index. +@@ -486,5 +492,5 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) + synchronize_flags); + + notmuch_database_destroy (notmuch); +- return EXIT_SUCCESS; ++ return INSERT_EXIT_SUCCESS; + } +diff --git a/test/T070-insert.sh b/test/T070-insert.sh +index ea9db07..c576efc 100755 +--- a/test/T070-insert.sh ++++ b/test/T070-insert.sh +@@ -18,7 +18,7 @@ gen_insert_msg() { + "[body]=\"insert-message\"" + } + +-test_expect_code 1 "Insert zero-length file" \ ++test_expect_code 2 "Insert zero-length file" \ + "notmuch insert < /dev/null" + + # This test is a proxy for other errors that may occur while trying to +@@ -137,7 +137,7 @@ output=$(notmuch search --output=messages path:Drafts/cur tag:draft NOT tag:unre + test_expect_equal "$output" "id:$gen_msg_id" + + gen_insert_msg +-test_expect_code 1 "Insert message into non-existent folder" \ ++test_expect_code 2 "Insert message into non-existent folder" \ + "notmuch insert --folder=nonesuch < $gen_msg_filename" + + test_begin_subtest "Insert message, create folder" +-- +1.8.4 + -- 2.26.2