[issue30400] Race condition in shutil.copyfile(): source file replaced file during copy

Giampaolo Rodola' report at bugs.python.org
Sat Jul 14 06:58:25 EDT 2018


Giampaolo Rodola' <g.rodola at gmail.com> added the comment:

> For example, os.stat() accepts both a filename (string) or a file descriptor (integer).

Interesting. I never realized that. Other functions involved in file copy are:

os.lchmod
os.chmod
os.listxattr
os.getxattr

I checked and it appears they all support fd args (this is not documented and it should). os.path.* all use os.stat() internally so they can easily be replaced. I wonder whether this can introduce any change in semantic though:

>>> import os
>>> os.stat('foobar')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'foobar'
>>> os.stat(333)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 9] Bad file descriptor: 333

Also wonder it this would play nice on Windows.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue30400>
_______________________________________


More information about the Python-bugs-list mailing list