From 9c4ea2a7a6a7f4cd5e84b5c889edfc95c266f29d Mon Sep 17 00:00:00 2001 From: Peter Wang Date: Mon, 19 Nov 2012 23:26:51 +1100 Subject: [PATCH] Re: [PATCH 05/18] insert: move file from Maildir tmp to new --- bc/6605d2f243c414cec7e3ef24f5281c1094caa5 | 123 ++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 bc/6605d2f243c414cec7e3ef24f5281c1094caa5 diff --git a/bc/6605d2f243c414cec7e3ef24f5281c1094caa5 b/bc/6605d2f243c414cec7e3ef24f5281c1094caa5 new file mode 100644 index 000000000..62debbb73 --- /dev/null +++ b/bc/6605d2f243c414cec7e3ef24f5281c1094caa5 @@ -0,0 +1,123 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id A2824431FBF + for ; Mon, 19 Nov 2012 04:26:59 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.799 +X-Spam-Level: +X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id cPJ7m3Dt8a+u for ; + Mon, 19 Nov 2012 04:26:58 -0800 (PST) +Received: from mail-pa0-f53.google.com (mail-pa0-f53.google.com + [209.85.220.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 7A460431FBC + for ; Mon, 19 Nov 2012 04:26:58 -0800 (PST) +Received: by mail-pa0-f53.google.com with SMTP id bj3so3864810pad.26 + for ; Mon, 19 Nov 2012 04:26:57 -0800 (PST) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=date:message-id:from:to:cc:subject:in-reply-to:references + :mime-version:content-type:content-disposition + :content-transfer-encoding; + bh=JhwmViI9MvEQAzpH7eFM97MVgWkcIQlRYZUYpavf1uE=; + b=uhoyH/0mfUhzswbl6TQpnkUZ7Cjg7Aq61I8DsO9SKesOCQL4RCSlMi+yg/SL8dWJWa + ssRl1aaO2Jr0VnWZeOIKuuXjkAaZrL3FfbWh/roXuN480J0I1G7PdPDVoHgyJLzyqNdw + oULm2t6QJPvMs6dil/+mqJsCE3avEtAvMnSpFClmSPUqhCjAnB843w9dj3pfCZ/8XhzN + Ajawf2Rfx6WW4/RdMcTbXL4CDCRT7MPkKibwtoviBDWYc8RYaNM58OSK0/NFt/ldMhn0 + ihhtqphPrBS4fjUu9BJZNLxFvcWm6WYqazRAG36cUkoB21hmA6y3PJ3JQs1GtP6inZAS + O24g== +Received: by 10.68.231.69 with SMTP id te5mr37984833pbc.81.1353328016628; + Mon, 19 Nov 2012 04:26:56 -0800 (PST) +Received: from localhost (215.42.233.220.static.exetel.com.au. + [220.233.42.215]) + by mx.google.com with ESMTPS id gu5sm6163419pbc.10.2012.11.19.04.26.53 + (version=TLSv1/SSLv3 cipher=OTHER); + Mon, 19 Nov 2012 04:26:55 -0800 (PST) +Date: Mon, 19 Nov 2012 23:26:51 +1100 +Message-ID: <20121119232651.GB2063@hili.localdomain> +From: Peter Wang +To: Mark Walters +Subject: Re: [PATCH 05/18] insert: move file from Maildir tmp to new +In-Reply-To: <87haomq0hx.fsf@qmul.ac.uk> +References: <1343223767-9812-1-git-send-email-novalazy@gmail.com> + <1343223767-9812-5-git-send-email-novalazy@gmail.com> + <87haomq0hx.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=utf-8 +Content-Disposition: inline +Content-Transfer-Encoding: 8bit +Cc: notmuch@notmuchmail.org +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Mon, 19 Nov 2012 12:26:59 -0000 + +On Sun, 18 Nov 2012 17:33:46 +0000, Mark Walters wrote: +> On Wed, 25 Jul 2012, Peter Wang wrote: +> > Atomically move the new message file from the Maildir 'tmp' directory +> > to 'new'. +> > --- +> > notmuch-insert.c | 18 ++++++++++++++++++ +> > 1 files changed, 18 insertions(+), 0 deletions(-) +> > +> > diff --git a/notmuch-insert.c b/notmuch-insert.c +> > index 340f7e4..bab1fed 100644 +> > --- a/notmuch-insert.c +> > +++ b/notmuch-insert.c +> > @@ -75,6 +75,20 @@ maildir_open_tmp (void *ctx, const char *dir, char **tmppath, char **newpath) +> > } +> > +> > static notmuch_bool_t +> > +maildir_move_to_new (const char *tmppath, const char *newpath) +> > +{ +> > + /* We follow the Dovecot recommendation to simply use rename() +> > + * instead of link() and unlink(). +> > + */ +> > + if (rename (tmppath, newpath) == 0) { +> > + return TRUE; +> > + } +> +> Do we want to overwrite an existing message with this name? As far as I +> can see rename does overwrite and link would not: was that why rename is +> better than link/unlink? +> +> I would prefer not to overwrite but maybe there is a reason we need to. +> Would a possible alternative be to loop when finding a tmp file until +> both the tmp file and the new file do not exist? + +According to [1] it's all pointless -- just generate unique file names. + +The dovecot maildir-save.c has this comment: + +/* maildir spec says we should use link() + unlink() here. however + since our filename is guaranteed to be unique, rename() works just + as well, except faster. even if the filename wasn't unique, the + problem could still happen if the file was already moved from + new/ to cur/, so link() doesn't really provide any safety anyway. + + Besides the small temporary performance benefits, this rename() is + almost required with OSX's HFS+ filesystem, since it implements + hard links in a pretty ugly way, which makes the performance crawl + when a lot of hard links are used. */ + +Well, that's one point of view. I can't say I know any better. + +Peter + +[1]: http://wiki.dovecot.org/MailboxFormat/Maildir#Mail_delivery -- 2.26.2