--- /dev/null
+Return-Path: <novalazy@gmail.com>\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 1F924431FB6\r
+ for <notmuch@notmuchmail.org>; Sun, 23 Jun 2013 05:20:00 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_FROM=0.001, 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 TgnN++6RnrOF for <notmuch@notmuchmail.org>;\r
+ Sun, 23 Jun 2013 05:19:51 -0700 (PDT)\r
+Received: from mail-pa0-f41.google.com (mail-pa0-f41.google.com\r
+ [209.85.220.41]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 2F58B431FAE\r
+ for <notmuch@notmuchmail.org>; Sun, 23 Jun 2013 05:19:51 -0700 (PDT)\r
+Received: by mail-pa0-f41.google.com with SMTP id bj3so9838371pad.0\r
+ for <notmuch@notmuchmail.org>; Sun, 23 Jun 2013 05:19:50 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=date:message-id:from:to:cc:subject:in-reply-to:references\r
+ :mime-version:content-type:content-disposition\r
+ :content-transfer-encoding;\r
+ bh=ZW6UzJMwrRRJSXPcRbbiWxrZ+/TepwD+4SVexBmvwQQ=;\r
+ b=qINvEgDsn5Ss7pmOy2YbNEETI3t+L2MuEt8sNB2Oam3/BlvMXtpUqKz88F7ZlTUbbt\r
+ fT3pdIcw9amIjFoBJz0tcsxgGycAi0vEJABBz4NPaARtilglz6iQ1oMNx3tv08k+Ad2W\r
+ 8iN++1zrWhbbqKbdX0O1Xem+wOmNI44dGgHIrEKn6OkbB5k2dv4zBVfLuUs6J6dmzy7I\r
+ WvJAxOGszZf15AGnW8f81acq0jOFQIt5PxlpX/8oM+fC0xJSI/IZaZY/Os5egT8DqbgR\r
+ aOPgczQ2lHGF/LVAFZHglYldfAIrygdp2PM2wtpOXrsKli4jFUrDEz4rAdeQWI3xM+dM\r
+ w48Q==\r
+X-Received: by 10.66.160.97 with SMTP id xj1mr12932797pab.5.1371989988343;\r
+ Sun, 23 Jun 2013 05:19:48 -0700 (PDT)\r
+Received: from localhost (215.42.233.220.static.exetel.com.au.\r
+ [220.233.42.215])\r
+ by mx.google.com with ESMTPSA id ri8sm13336924pbc.3.2013.06.23.05.19.45\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Sun, 23 Jun 2013 05:19:47 -0700 (PDT)\r
+Date: Sun, 23 Jun 2013 22:19:42 +1000\r
+Message-ID: <20130623221942.GA18938@hili.localdomain>\r
+From: Peter Wang <novalazy@gmail.com>\r
+To: Mark Walters <markwalters1009@gmail.com>\r
+Subject: Re: [PATCH v7 03/12] cli: add insert command\r
+In-Reply-To: <8761x5uy3a.fsf@qmul.ac.uk>\r
+References: <1371961445-15182-1-git-send-email-novalazy@gmail.com>\r
+ <1371961445-15182-4-git-send-email-novalazy@gmail.com>\r
+ <8761x5uy3a.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Disposition: inline\r
+Content-Transfer-Encoding: 8bit\r
+Cc: notmuch@notmuchmail.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: Sun, 23 Jun 2013 12:20:00 -0000\r
+\r
+On Sun, 23 Jun 2013 07:42:49 +0100, Mark Walters <markwalters1009@gmail.com> wrote:\r
+> \r
+> This is a +1 modulo one small bug (I think) I found below. I am happy to\r
+> delay the fail-on-index-fail option, especially as that will need some\r
+> bikeshedding on its name.\r
+> \r
+> Also when posting new versions please include a diff from the previous\r
+> version (this is more difficult if there was significant rebasing). This\r
+> makew the v6 to v7 change obvious (the one comment change and the\r
+> bugfix).\r
+> \r
+> Moreover doing the diff with v4 (which I happen to have locally) I\r
+> found the bug below.\r
+> \r
+> Best wishes\r
+> \r
+> Mark\r
+> \r
+> \r
+> \r
+...\r
+> > +static notmuch_bool_t\r
+> > +insert_message (void *ctx, notmuch_database_t *notmuch, int fdin,\r
+> > + const char *dir, tag_op_list_t *tag_ops)\r
+> > +{\r
+> > + char *tmppath;\r
+> > + char *newpath;\r
+> > + char *newdir;\r
+> > + int fdout;\r
+> > + char *cleanup_path;\r
+> > +\r
+> > + fdout = maildir_open_tmp_file (ctx, dir, &tmppath, &newpath, &newdir);\r
+> > + if (fdout < 0)\r
+> > + return FALSE;\r
+> > +\r
+> > + cleanup_path = tmppath;\r
+> > +\r
+> > + if (! copy_stdin (fdin, fdout))\r
+> > + goto FAIL;\r
+> > +\r
+> > + if (fsync (fdout) != 0) {\r
+> > + fprintf (stderr, "Error: fsync failed: %s\n", strerror (errno));\r
+> > + goto FAIL;\r
+> > + }\r
+> > +\r
+> > + close (fdout);\r
+> > + fdout = -1;\r
+> > +\r
+> > + /* Atomically move the new message file from the Maildir 'tmp' directory\r
+> > + * to the 'new' directory. We follow the Dovecot recommendation to\r
+> > + * simply use rename() instead of link() and unlink().\r
+> > + * See also: http://wiki.dovecot.org/MailboxFormat/Maildir#Mail_delivery\r
+> > + */\r
+> > + if (rename (tmppath, newpath) != 0) {\r
+> > + fprintf (stderr, "Error: rename() failed: %s\n", strerror (errno));\r
+> > + goto FAIL;\r
+> > + }\r
+> > +\r
+> > + if (! sync_dir (newdir))\r
+> > + goto FAIL;\r
+> \r
+> I think cleanup_path needs to be updated before the sync_dir is test as\r
+> newpath should be unlinked rather than oldpath. (v4 explicitly unlinked newpath)\r
+> \r
+\r
+Thanks for the continued close review.\r
+I'll post a followup to this specific patch.\r
+\r
+Peter\r