--- /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 A2824431FBF\r
+ for <notmuch@notmuchmail.org>; Mon, 19 Nov 2012 04:26:59 -0800 (PST)\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 cPJ7m3Dt8a+u for <notmuch@notmuchmail.org>;\r
+ Mon, 19 Nov 2012 04:26:58 -0800 (PST)\r
+Received: from mail-pa0-f53.google.com (mail-pa0-f53.google.com\r
+ [209.85.220.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 7A460431FBC\r
+ for <notmuch@notmuchmail.org>; Mon, 19 Nov 2012 04:26:58 -0800 (PST)\r
+Received: by mail-pa0-f53.google.com with SMTP id bj3so3864810pad.26\r
+ for <notmuch@notmuchmail.org>; Mon, 19 Nov 2012 04:26:57 -0800 (PST)\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=JhwmViI9MvEQAzpH7eFM97MVgWkcIQlRYZUYpavf1uE=;\r
+ b=uhoyH/0mfUhzswbl6TQpnkUZ7Cjg7Aq61I8DsO9SKesOCQL4RCSlMi+yg/SL8dWJWa\r
+ ssRl1aaO2Jr0VnWZeOIKuuXjkAaZrL3FfbWh/roXuN480J0I1G7PdPDVoHgyJLzyqNdw\r
+ oULm2t6QJPvMs6dil/+mqJsCE3avEtAvMnSpFClmSPUqhCjAnB843w9dj3pfCZ/8XhzN\r
+ Ajawf2Rfx6WW4/RdMcTbXL4CDCRT7MPkKibwtoviBDWYc8RYaNM58OSK0/NFt/ldMhn0\r
+ ihhtqphPrBS4fjUu9BJZNLxFvcWm6WYqazRAG36cUkoB21hmA6y3PJ3JQs1GtP6inZAS\r
+ O24g==\r
+Received: by 10.68.231.69 with SMTP id te5mr37984833pbc.81.1353328016628;\r
+ Mon, 19 Nov 2012 04:26:56 -0800 (PST)\r
+Received: from localhost (215.42.233.220.static.exetel.com.au.\r
+ [220.233.42.215])\r
+ by mx.google.com with ESMTPS id gu5sm6163419pbc.10.2012.11.19.04.26.53\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Mon, 19 Nov 2012 04:26:55 -0800 (PST)\r
+Date: Mon, 19 Nov 2012 23:26:51 +1100\r
+Message-ID: <20121119232651.GB2063@hili.localdomain>\r
+From: Peter Wang <novalazy@gmail.com>\r
+To: Mark Walters <markwalters1009@gmail.com>\r
+Subject: Re: [PATCH 05/18] insert: move file from Maildir tmp to new\r
+In-Reply-To: <87haomq0hx.fsf@qmul.ac.uk>\r
+References: <1343223767-9812-1-git-send-email-novalazy@gmail.com>\r
+ <1343223767-9812-5-git-send-email-novalazy@gmail.com>\r
+ <87haomq0hx.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: Mon, 19 Nov 2012 12:26:59 -0000\r
+\r
+On Sun, 18 Nov 2012 17:33:46 +0000, Mark Walters <markwalters1009@gmail.com> wrote:\r
+> On Wed, 25 Jul 2012, Peter Wang <novalazy@gmail.com> wrote:\r
+> > Atomically move the new message file from the Maildir 'tmp' directory\r
+> > to 'new'.\r
+> > ---\r
+> > notmuch-insert.c | 18 ++++++++++++++++++\r
+> > 1 files changed, 18 insertions(+), 0 deletions(-)\r
+> >\r
+> > diff --git a/notmuch-insert.c b/notmuch-insert.c\r
+> > index 340f7e4..bab1fed 100644\r
+> > --- a/notmuch-insert.c\r
+> > +++ b/notmuch-insert.c\r
+> > @@ -75,6 +75,20 @@ maildir_open_tmp (void *ctx, const char *dir, char **tmppath, char **newpath)\r
+> > }\r
+> > \r
+> > static notmuch_bool_t\r
+> > +maildir_move_to_new (const char *tmppath, const char *newpath)\r
+> > +{\r
+> > + /* We follow the Dovecot recommendation to simply use rename()\r
+> > + * instead of link() and unlink().\r
+> > + */\r
+> > + if (rename (tmppath, newpath) == 0) {\r
+> > + return TRUE;\r
+> > + }\r
+> \r
+> Do we want to overwrite an existing message with this name? As far as I\r
+> can see rename does overwrite and link would not: was that why rename is\r
+> better than link/unlink?\r
+> \r
+> I would prefer not to overwrite but maybe there is a reason we need to. \r
+> Would a possible alternative be to loop when finding a tmp file until\r
+> both the tmp file and the new file do not exist?\r
+\r
+According to [1] it's all pointless -- just generate unique file names.\r
+\r
+The dovecot maildir-save.c has this comment:\r
+\r
+/* maildir spec says we should use link() + unlink() here. however\r
+ since our filename is guaranteed to be unique, rename() works just\r
+ as well, except faster. even if the filename wasn't unique, the\r
+ problem could still happen if the file was already moved from\r
+ new/ to cur/, so link() doesn't really provide any safety anyway.\r
+\r
+ Besides the small temporary performance benefits, this rename() is\r
+ almost required with OSX's HFS+ filesystem, since it implements\r
+ hard links in a pretty ugly way, which makes the performance crawl\r
+ when a lot of hard links are used. */\r
+\r
+Well, that's one point of view. I can't say I know any better.\r
+\r
+Peter\r
+\r
+[1]: http://wiki.dovecot.org/MailboxFormat/Maildir#Mail_delivery\r