Re: [PATCH 05/18] insert: move file from Maildir tmp to new
authorMark Walters <markwalters1009@gmail.com>
Mon, 19 Nov 2012 13:49:05 +0000 (13:49 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:50:45 +0000 (09:50 -0800)
2b/f11a76c0689cfb3930658946a36c7dc7f281f6 [new file with mode: 0644]

diff --git a/2b/f11a76c0689cfb3930658946a36c7dc7f281f6 b/2b/f11a76c0689cfb3930658946a36c7dc7f281f6
new file mode 100644 (file)
index 0000000..161739c
--- /dev/null
@@ -0,0 +1,144 @@
+Return-Path: <m.walters@qmul.ac.uk>\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 8FD90431FC0\r
+       for <notmuch@notmuchmail.org>; Mon, 19 Nov 2012 05:49:19 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.098\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
+       tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+       NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 OuKFUkF8F2Tt for <notmuch@notmuchmail.org>;\r
+       Mon, 19 Nov 2012 05:49:18 -0800 (PST)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 83905431FBC\r
+       for <notmuch@notmuchmail.org>; Mon, 19 Nov 2012 05:49:18 -0800 (PST)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+       by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+       (envelope-from <m.walters@qmul.ac.uk>)\r
+       id 1TaRil-0001PR-Lr; Mon, 19 Nov 2012 13:49:12 +0000\r
+Received: from 93-97-24-31.zone5.bethere.co.uk ([93.97.24.31] helo=localhost)\r
+       by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
+       (envelope-from <m.walters@qmul.ac.uk>)\r
+       id 1TaRil-00075M-Be; Mon, 19 Nov 2012 13:49:07 +0000\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Peter Wang <novalazy@gmail.com>\r
+Subject: Re: [PATCH 05/18] insert: move file from Maildir tmp to new\r
+In-Reply-To: <20121119232651.GB2063@hili.localdomain>\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
+       <20121119232651.GB2063@hili.localdomain>\r
+User-Agent: Notmuch/0.14+81~g9730584 (http://notmuchmail.org) Emacs/23.4.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Mon, 19 Nov 2012 13:49:05 +0000\r
+Message-ID: <874nklpusu.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 93.97.24.31\r
+X-QM-SPAM-Info: Sender has good ham record.  :)\r
+X-QM-Body-MD5: 59b428e578dce949411df32e677a0de0 (of first 20000 bytes)\r
+X-SpamAssassin-Score: -1.8\r
+X-SpamAssassin-SpamBar: -\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+       determine if it is\r
+       spam. We require at least 5.0 points to mark a message as spam.\r
+       This message scored -1.8 points.\r
+       Summary of the scoring: \r
+       * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
+       *      medium trust\r
+       *      [138.37.6.40 listed in list.dnswl.org]\r
+       * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+       provider *      (markwalters1009[at]gmail.com)\r
+       *  0.5 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\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 13:49:19 -0000\r
+\r
+\r
+Hi \r
+\r
+On Mon, 19 Nov 2012, Peter Wang <novalazy@gmail.com> wrote:\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
+I think I agree with you/them. Indeed, since files in cur can have\r
+maildir flags we could find that this rename works but then the new file\r
+gets stomped on by notmuch_message_tags_to_maildir_flags which also uses\r
+rename. It might be work adding the link to [1] in the comment, but in\r
+any case I am happy with this now.\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+>\r
+> Peter\r
+>\r
+> [1]: http://wiki.dovecot.org/MailboxFormat/Maildir#Mail_delivery\r