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 64F50431FDC
\r
6 for <notmuch@notmuchmail.org>; Wed, 16 Apr 2014 06:00:43 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.799 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_LOW=-0.7] 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 agypQVppRV2o for <notmuch@notmuchmail.org>;
\r
17 Wed, 16 Apr 2014 06:00:36 -0700 (PDT)
\r
18 Received: from mail-pa0-f42.google.com (mail-pa0-f42.google.com
\r
19 [209.85.220.42]) (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 CC304431FDE
\r
22 for <notmuch@notmuchmail.org>; Wed, 16 Apr 2014 06:00:08 -0700 (PDT)
\r
23 Received: by mail-pa0-f42.google.com with SMTP id fb1so10923726pad.15
\r
24 for <notmuch@notmuchmail.org>; Wed, 16 Apr 2014 06:00:08 -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=+HXB+LTFJM7wRO+0IUZtPIGOPE0vuuNVAiMcp6D0URY=;
\r
28 b=xwFlwQtDx3+GR7nzOj50kSJpSQe9T4LCfBtxVQt5ffcLhrogq/uxmEr++0zCr0EjMb
\r
29 uWW9NTCQbI0H2K6mDTVkiC2QYe4J1G9dwGXfHK8OT67Ipx7vNzPD4WBRJh5kSiT5hdNz
\r
30 rChslUwKHAUGCHYWur8gxtpfXFJRXyL/vtXY3NHBtsfeVlZhInAjCBKYM4lzwtwRLbni
\r
31 qMMjZvdOr7IRi9FJl8291ZfDUwiZHxW0ehi7j1Ekzso16uC0fGZ6ze7G2Blnh+ayvbuM
\r
32 offBDzj48qvBeQcINLgVDlTaWatbUXazOgM1UejLnFRSl8ADB2Q9dIM6Hor++XX25dW+
\r
34 X-Received: by 10.68.143.196 with SMTP id sg4mr8185642pbb.155.1397653208034;
\r
35 Wed, 16 Apr 2014 06:00:08 -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 hw8sm46903968pbc.62.2014.04.16.06.00.06 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:07 -0700 (PDT)
\r
41 From: Peter Wang <novalazy@gmail.com>
\r
42 To: notmuch@notmuchmail.org
\r
43 Subject: [PATCH v2 06/10] cli: refactor insert
\r
44 Date: Wed, 16 Apr 2014 22:59:21 +1000
\r
45 Message-Id: <1397653165-15620-7-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:43 -0000
\r
63 Change insert_message into write_message and move its responsibilities
\r
64 for indexing the message into the main function, to simplify the control
\r
67 notmuch-insert.c | 63 +++++++++++++++++++++++++++-----------------------------
\r
68 1 file changed, 30 insertions(+), 33 deletions(-)
\r
70 diff --git a/notmuch-insert.c b/notmuch-insert.c
\r
71 index 6752fc8..7db4f73 100644
\r
72 --- a/notmuch-insert.c
\r
73 +++ b/notmuch-insert.c
\r
74 @@ -338,59 +338,48 @@ add_file_to_database (notmuch_database_t *notmuch, const char *path,
\r
77 static notmuch_bool_t
\r
78 -insert_message (void *ctx, notmuch_database_t *notmuch, int fdin,
\r
79 - const char *dir, tag_op_list_t *tag_ops,
\r
80 - notmuch_bool_t synchronize_flags)
\r
81 +write_message (void *ctx, int fdin, const char *dir, char **newpath)
\r
87 - char *cleanup_path;
\r
89 - fdout = maildir_open_tmp_file (ctx, dir, &tmppath, &newpath, &newdir);
\r
90 + fdout = maildir_open_tmp_file (ctx, dir, &tmppath, newpath, &newdir);
\r
94 - cleanup_path = tmppath;
\r
96 - if (! copy_stdin (fdin, fdout))
\r
98 + if (! copy_stdin (fdin, fdout)) {
\r
100 + unlink (tmppath);
\r
104 if (fsync (fdout) != 0) {
\r
105 fprintf (stderr, "Error: fsync failed: %s\n", strerror (errno));
\r
108 + unlink (tmppath);
\r
115 /* Atomically move the new message file from the Maildir 'tmp' directory
\r
116 * to the 'new' directory. We follow the Dovecot recommendation to
\r
117 * simply use rename() instead of link() and unlink().
\r
118 * See also: http://wiki.dovecot.org/MailboxFormat/Maildir#Mail_delivery
\r
120 - if (rename (tmppath, newpath) != 0) {
\r
121 + if (rename (tmppath, *newpath) != 0) {
\r
122 fprintf (stderr, "Error: rename() failed: %s\n", strerror (errno));
\r
124 + unlink (tmppath);
\r
128 - cleanup_path = newpath;
\r
130 - if (! sync_dir (newdir))
\r
133 - /* Even if adding the message to the notmuch database fails,
\r
134 - * the message is on disk and we consider the delivery completed. */
\r
135 - add_file_to_database (notmuch, newpath, tag_ops, synchronize_flags);
\r
136 + if (! sync_dir (newdir)) {
\r
137 + unlink (*newpath);
\r
146 - unlink (cleanup_path);
\r
151 @@ -407,9 +396,9 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
\r
152 notmuch_bool_t create_folder = FALSE;
\r
153 notmuch_bool_t synchronize_flags;
\r
154 const char *maildir;
\r
158 - notmuch_bool_t ret;
\r
160 notmuch_opt_desc_t options[] = {
\r
161 { NOTMUCH_OPT_STRING, &folder, "folder", 0, 0 },
\r
162 @@ -484,10 +473,18 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
\r
163 NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
\r
164 return EXIT_FAILURE;
\r
166 - ret = insert_message (config, notmuch, STDIN_FILENO, maildir, tag_ops,
\r
167 - synchronize_flags);
\r
168 + /* Write the message to the Maildir new directory. */
\r
169 + if (! write_message (config, STDIN_FILENO, maildir, &newpath)) {
\r
170 + notmuch_database_destroy (notmuch);
\r
171 + return EXIT_FAILURE;
\r
174 - notmuch_database_destroy (notmuch);
\r
175 + /* Add the message to the index.
\r
176 + * Even if adding the message to the notmuch database fails,
\r
177 + * the message is on disk and we consider the delivery completed. */
\r
178 + add_file_to_database (notmuch, newpath, tag_ops,
\r
179 + synchronize_flags);
\r
181 - return ret ? EXIT_SUCCESS : EXIT_FAILURE;
\r
182 + notmuch_database_destroy (notmuch);
\r
183 + return EXIT_SUCCESS;
\r