Message25571
os.makedirs() can fail if one of its components is
created while it is running (perhaps by another
process). This is because it checks for each directory
if it exists before creating it.
This is bad programming style. A correct implementation
would just call mkdir() on each directory (starting
with the rightmost, probably) and ignoring any EEXIST
error. This would not only fix the bug, it would also
be faster (fewer syscalls).
The patch is simple, but there is a wart in the design:
os.makedirs() throws an error if the (rightmost)
directory already exists, although by calling this
function the user has clearly indicated that she wants
the directories to be created if they don't exist and
have no complaints otherwise.
This leads to code like:
try:
os.makedirs(path)
except OSError:
pass
which is doubly bad because it hides the race condition!
So, before I submit a patch, should we:
a) just fix this bug but keep the old design
b) fix this bug, and don't throw an error if the dir exists
or maybe do a) for the next 2.4.x bugfix release and b)
in 2.5?
|
|
Date |
User |
Action |
Args |
2007-08-23 14:32:31 | admin | link | issue1223238 messages |
2007-08-23 14:32:31 | admin | create | |
|