1 Return-Path: <novalazy@gmail.com>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 94A2D429E37
\r
6 for <notmuch@notmuchmail.org>; Wed, 16 Apr 2014 06:00:45 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.099 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id XVBqombZ+Pgv for <notmuch@notmuchmail.org>;
\r
17 Wed, 16 Apr 2014 06:00:40 -0700 (PDT)
\r
18 Received: from mail-pd0-f169.google.com (mail-pd0-f169.google.com
\r
19 [209.85.192.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 26E41431FAE
\r
22 for <notmuch@notmuchmail.org>; Wed, 16 Apr 2014 06:00:13 -0700 (PDT)
\r
23 Received: by mail-pd0-f169.google.com with SMTP id fp1so10780476pdb.0
\r
24 for <notmuch@notmuchmail.org>; Wed, 16 Apr 2014 06:00:12 -0700 (PDT)
\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
\r
26 h=from:to:cc:subject:date:message-id:in-reply-to:references;
\r
27 bh=q8S0uIz/2t/fjxsh5T+/4TYA1Qp5sSDOxaIQGwwRb3Q=;
\r
28 b=fUs0nYv7GbJklSB7pj5dVpsCvXra558t8RckqiFdGOnWNAeeaxxhOcLf4g53JUJ5ZJ
\r
29 zozZqaod/BWvRQc7SEDzwbdfn1WrTQAHg8lCAHqc0P3K2BdKOw6tttt5xaMKhoZ3UNeX
\r
30 xxEvWUV4C53jmJfZ5hydmpaSVSRKd6h/68WlcTpbs7BkWS94n4BYtVPxuole+x+7BUlW
\r
31 YvMiHdcq/gL9NS/zS/TdE4R7i9svnRMYpKmSfpaWSNI7IosnKstZhuMYCd79cmm5uQNx
\r
32 8Er3jxV5N25yFzlJZApqQU7KHawPszIgX1bokL9mZv/oxPa6I7kkhdhj8p/B4dGUo1Gq
\r
34 X-Received: by 10.66.102.72 with SMTP id fm8mr2695390pab.86.1397653212449;
\r
35 Wed, 16 Apr 2014 06:00:12 -0700 (PDT)
\r
36 Received: from localhost (215.42.233.220.static.exetel.com.au.
\r
37 [220.233.42.215]) by mx.google.com with ESMTPSA id
\r
38 nx12sm111066548pab.6.2014.04.16.06.00.10 for <multiple recipients>
\r
39 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
\r
40 Wed, 16 Apr 2014 06:00:11 -0700 (PDT)
\r
41 From: Peter Wang <novalazy@gmail.com>
\r
42 To: notmuch@notmuchmail.org
\r
43 Subject: [PATCH v2 07/10] cli: indicate insert failure mode in exit status
\r
44 Date: Wed, 16 Apr 2014 22:59:22 +1000
\r
45 Message-Id: <1397653165-15620-8-git-send-email-novalazy@gmail.com>
\r
46 X-Mailer: git-send-email 1.8.4
\r
47 In-Reply-To: <1397653165-15620-1-git-send-email-novalazy@gmail.com>
\r
48 References: <1397653165-15620-1-git-send-email-novalazy@gmail.com>
\r
49 X-BeenThere: notmuch@notmuchmail.org
\r
50 X-Mailman-Version: 2.1.13
\r
52 List-Id: "Use and development of the notmuch mail system."
\r
53 <notmuch.notmuchmail.org>
\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
55 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
57 List-Post: <mailto:notmuch@notmuchmail.org>
\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
60 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
61 X-List-Received-Date: Wed, 16 Apr 2014 13:00:45 -0000
\r
63 Make insert return a different exit code, 2, for failure to write the
\r
64 message file to disk, and exit code 1 for other errors.
\r
66 notmuch-insert.c | 30 ++++++++++++++++++------------
\r
67 test/T070-insert.sh | 4 ++--
\r
68 2 files changed, 20 insertions(+), 14 deletions(-)
\r
70 diff --git a/notmuch-insert.c b/notmuch-insert.c
\r
71 index 7db4f73..29d82c9 100644
\r
72 --- a/notmuch-insert.c
\r
73 +++ b/notmuch-insert.c
\r
75 #include <sys/stat.h>
\r
79 + INSERT_EXIT_SUCCESS = 0,
\r
80 + INSERT_EXIT_FAILURE = 1,
\r
81 + INSERT_EXIT_FAILED_WRITE = 2
\r
84 static volatile sig_atomic_t interrupted;
\r
87 @@ -408,7 +414,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
\r
89 opt_index = parse_arguments (argc, argv, options, 1);
\r
91 - return EXIT_FAILURE;
\r
92 + return INSERT_EXIT_FAILURE;
\r
94 db_path = notmuch_config_get_database_path (config);
\r
95 new_tags = notmuch_config_get_new_tags (config, &new_tags_length);
\r
96 @@ -417,7 +423,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
\r
97 tag_ops = tag_op_list_create (config);
\r
98 if (tag_ops == NULL) {
\r
99 fprintf (stderr, "Out of memory.\n");
\r
100 - return EXIT_FAILURE;
\r
101 + return INSERT_EXIT_FAILURE;
\r
103 for (i = 0; i < new_tags_length; i++) {
\r
104 const char *error_msg;
\r
105 @@ -426,20 +432,20 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
\r
107 fprintf (stderr, "Error: tag '%s' in new.tags: %s\n",
\r
108 new_tags[i], error_msg);
\r
109 - return EXIT_FAILURE;
\r
110 + return INSERT_EXIT_FAILURE;
\r
113 if (tag_op_list_append (tag_ops, new_tags[i], FALSE))
\r
114 - return EXIT_FAILURE;
\r
115 + return INSERT_EXIT_FAILURE;
\r
118 if (parse_tag_command_line (config, argc - opt_index, argv + opt_index,
\r
119 &query_string, tag_ops))
\r
120 - return EXIT_FAILURE;
\r
121 + return INSERT_EXIT_FAILURE;
\r
123 if (*query_string != '\0') {
\r
124 fprintf (stderr, "Error: unexpected query string: %s\n", query_string);
\r
125 - return EXIT_FAILURE;
\r
126 + return INSERT_EXIT_FAILURE;
\r
129 if (folder == NULL) {
\r
130 @@ -447,17 +453,17 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
\r
132 if (! check_folder_name (folder)) {
\r
133 fprintf (stderr, "Error: bad folder name: %s\n", folder);
\r
134 - return EXIT_FAILURE;
\r
135 + return INSERT_EXIT_FAILURE;
\r
137 maildir = talloc_asprintf (config, "%s/%s", db_path, folder);
\r
139 fprintf (stderr, "Out of memory\n");
\r
140 - return EXIT_FAILURE;
\r
141 + return INSERT_EXIT_FAILURE;
\r
143 if (create_folder && ! maildir_create_folder (config, maildir)) {
\r
144 fprintf (stderr, "Error: creating maildir %s: %s\n",
\r
145 maildir, strerror (errno));
\r
146 - return EXIT_FAILURE;
\r
147 + return INSERT_EXIT_FAILURE;
\r
151 @@ -471,12 +477,12 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
\r
153 if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
154 NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
\r
155 - return EXIT_FAILURE;
\r
156 + return INSERT_EXIT_FAILURE;
\r
158 /* Write the message to the Maildir new directory. */
\r
159 if (! write_message (config, STDIN_FILENO, maildir, &newpath)) {
\r
160 notmuch_database_destroy (notmuch);
\r
161 - return EXIT_FAILURE;
\r
162 + return INSERT_EXIT_FAILED_WRITE;
\r
165 /* Add the message to the index.
\r
166 @@ -486,5 +492,5 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
\r
167 synchronize_flags);
\r
169 notmuch_database_destroy (notmuch);
\r
170 - return EXIT_SUCCESS;
\r
171 + return INSERT_EXIT_SUCCESS;
\r
173 diff --git a/test/T070-insert.sh b/test/T070-insert.sh
\r
174 index ea9db07..c576efc 100755
\r
175 --- a/test/T070-insert.sh
\r
176 +++ b/test/T070-insert.sh
\r
177 @@ -18,7 +18,7 @@ gen_insert_msg() {
\r
178 "[body]=\"insert-message\""
\r
181 -test_expect_code 1 "Insert zero-length file" \
\r
182 +test_expect_code 2 "Insert zero-length file" \
\r
183 "notmuch insert < /dev/null"
\r
185 # This test is a proxy for other errors that may occur while trying to
\r
186 @@ -137,7 +137,7 @@ output=$(notmuch search --output=messages path:Drafts/cur tag:draft NOT tag:unre
\r
187 test_expect_equal "$output" "id:$gen_msg_id"
\r
190 -test_expect_code 1 "Insert message into non-existent folder" \
\r
191 +test_expect_code 2 "Insert message into non-existent folder" \
\r
192 "notmuch insert --folder=nonesuch < $gen_msg_filename"
\r
194 test_begin_subtest "Insert message, create folder"
\r