GNU bug report logs -
#41001
mkdir: cannot create directory ‘test’: File exists
Previous Next
Reported by: Jonny Grant <jg <at> jguk.org>
Date: Fri, 1 May 2020 15:16:01 UTC
Severity: normal
Tags: notabug
Done: Eric Blake <eblake <at> redhat.com>
Bug is archived. No further changes may be made.
Full log
Message #27 received at 41001 <at> debbugs.gnu.org (full text, mbox):
On 01/05/2020 21:32, Paul Eggert wrote:
> On 5/1/20 1:21 PM, Jonny Grant wrote:
>> yes, the fix pretty trivial for mkdir as you highlight EISDIR:
>> stat(), S_ISDIR(sb.st_mode), and set errno to EISDIR or output strerror(EISDIR)
>
> That would introduce a race condition, and wouldn't behave correctly if some
> other process changes the destination from a regular file to a directory between
> the time we call mkdir and the time that we call stat.
Paul,
If developers have race conditions in their shell scripts - mkdir error
string in the message after the colon in the output saying
file/directory is the least of the developers' problems.
mkdir() returning EEXIST only indicates the pathname exists.
Maybe call stat() before calling mkdir() to check nothing there. It's
more a question of doing something appropriate.
Personally I doubt POSIX will ever be updated to have more errno errors
that distinguish between files and directories for ENOENT and EEXIST due
to people's fears about compatibility when APIs are updated.
Cheers, Jonny
This bug report was last modified 5 years and 12 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.