unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: "Ciprian Dorin, Craciun" <ciprian.craciun@gmail.com>
To: notmuch <notmuch@notmuchmail.org>
Subject: Re: `notmuch setup` replaces `~/.notmuch-config` instead of truncating it
Date: Wed, 17 Nov 2010 00:16:07 +0200	[thread overview]
Message-ID: <AANLkTikMhb=x4jOhOwjP4Ytd+h=4f247ZnA3A0GOS=hC@mail.gmail.com> (raw)
In-Reply-To: <4CE2EB89.5040209@fifthhorseman.net>

On Tue, Nov 16, 2010 at 22:37, Daniel Kahn Gillmor
<dkg@fifthhorseman.net> wrote:
> On 11/16/2010 03:26 PM, Ciprian Dorin, Craciun wrote:
>>     P.S.: I say "pseudo" atomic because only the rename is atomic,
>> thus in order to override file `a` for the target file `b` which
>> exists, we must execute two **non-atomic** operations as a whole, but
>> each atomic in part, rename operations: make `b` -> `c`, and then
>> rename `a` -> `b`. So there is actually a small time-frame when I can
>> be left with two files (`a` and `c`), none of which is my config file
>> `b`. (This can be solved when opening the config file by checking if
>> there isn't any leftover `c` or `a` file, in which case I take the `a`
>> file and complete the rename.)
>
> There is only one ".notmuch-config" entry in the inode directory that is
> your homedir.  it points either to the old file, or the new file.  it
> cannot point to both, and it will not point to anything but those two
> possibilities.  This is what the atomicity of the operation is expected
> to guarantee.
>
>        --dkg


    Actually I've been wrong about this... I've thought that the way
the file is "overwritten" is actually done by either two `rename`
calls or by `link`, followed by another `link`, and then finally an
`unlink` (this is what I've tried to explain in my previous email).

    In fact I've thought that the `rename` OS call can't overwrite a
file if it exists.

    But after reading the man page of `rename(2)` -- quoted below -- I
was indeed wrong to call the atomicity as being "pseudo".

~~~~
       int rename(const char *oldpath, const char *newpath);
...
       If newpath already exists it will be atomically replaced
(subject to a few conditions; see ERRORS below),  so  that  there  is
no
       point at which another process attempting to access newpath
will find it missing.
...
       If newpath exists but the operation fails for some reason
rename() guarantees to leave an instance of newpath in place.
~~~~

    So indeed the behavior is completely atomic.

    Ciprian.

      parent reply	other threads:[~2010-11-16 22:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-16 13:33 `notmuch setup` replaces `~/.notmuch-config` instead of truncating it Ciprian Dorin, Craciun
2010-11-16 13:38 ` Jameson Rollins
2010-11-16 15:38   ` Daniel Kahn Gillmor
2010-11-16 19:09 ` Carl Worth
2010-11-16 20:26   ` Ciprian Dorin, Craciun
2010-11-16 20:37     ` Daniel Kahn Gillmor
2010-11-16 20:42       ` Daniel Kahn Gillmor
2010-11-16 22:17         ` Ciprian Dorin, Craciun
2010-11-16 22:16       ` Ciprian Dorin, Craciun [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='AANLkTikMhb=x4jOhOwjP4Ytd+h=4f247ZnA3A0GOS=hC@mail.gmail.com' \
    --to=ciprian.craciun@gmail.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).