Charles-François Natali <neolo...@free.fr> added the comment:

There's a race in _write_atomic():
"""
        # On POSIX-like platforms, renaming is atomic
        path_tmp = path + '.tmp'
        try:
            fd = _os.open(path_tmp, _os.O_EXCL | _os.O_CREAT | _os.O_WRONLY)
            with _io.FileIO(fd, 'wb') as file:
                file.write(data)
            _os.rename(path_tmp, path)
        except OSError:
            try:
                _os.unlink(path_tmp)
            except OSError:
                pass
            raise
"""

Let's pretend a process managed to open the file (with O_EXCL): before it 
finishes and calls rename(), another process tries to open the file: since it 
can't create it (with O_EXCL), it jumps to:

        except OSError:
            try:
                _os.unlink(path_tmp)
            except OSError:
                pass
            raise

and unlinks the file.
The first process then calls rename()...

----------
nosy: +neologix

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13303>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to