chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] [patch] remove the initial check on directory exista


From: Jim Ursetto
Subject: Re: [Chicken-users] [patch] remove the initial check on directory existance
Date: Sat, 2 Feb 2013 11:16:53 -0600

I am positive this is a case where the documentation was written
to explain an implementation artifact.  That note wasn't added
until 11 months ago ... by Mario.

The current implementation returns "foo" if a file foo
(not just a directory foo) already exists.  No one is
ever going to check this return value.  It seems to me
if regular file "foo" exists it should be an error.

I don't think it's atomic any more if you ignore EEXISTS, because

1) the existing directory could be owned by the wrong person
2) it might still be a regular file
3) when used to implement dotlocking, the caller needs to know
   whether EEXISTS was returned, akin to using O_CREATE|O_EXCL.

Unfortunately as Peter suggested, I doubt we could change the
behavior to error out when the directory exists, because some
code probably relies on it.

I think we could error out on regular file existing, i.e. change
file-exists? to directory-exists? or perhaps check type
after the fact on EEXISTS.

But making it atomic would probably require a new procedure name,
which does not check for existence beforehand and does not
ignore EEXISTS.  You could still ignore EEXISTS if creating
the full path (parents? == #t).  This is then like mkdir -p.
It's how I would expect it to behave and preserves atomicity.
This could potentially go in the posix-extras egg.

Jim

On Feb 2, 2013, at 9:57 AM, Mario Domenech Goulart wrote:

> Hi,
> 
> On Sat, 2 Feb 2013 16:54:19 +0100 Peter Bex <address@hidden> wrote:
> 
>> On Sun, Feb 03, 2013 at 02:20:59AM +1100, richo wrote:
>>> This patch removes the internal check for directory existance in
>>> create-directory, meaning that it can be treated as atomic on platforms 
>>> where mkdir(2) is.
>> 
>> This makes it inconsistent with the documentation (which, iiuc is already
>> the case on Windows).
>> 
>> I think this patch shouldn't go through, the behavior is wrong.
>> It's probably better to make it ignore EEXIST if you want it to be
>> atomic.
> 
> Also, it's likely to break code that relies on the current
> `create-directory' behavior.
> 
> OTOH, as far as I understand, the current `create-directory'
> implementation is subject to race conditions, since the check/create
> steps are not atomic.
> 
> Maybe it should just attempt to create the directory and ignore errors
> when it cannot be created because it exists (maybe that's what Peter
> suggests -- I'm not sure).
> 
> 
> Best wishes.
> Mario
> -- 
> http://parenteses.org/mario
> 
> _______________________________________________
> Chicken-users mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/chicken-users




reply via email to

[Prev in Thread] Current Thread [Next in Thread]