mirror of
https://github.com/python/cpython.git
synced 2025-10-07 15:42:02 +00:00
Issue #14077: importlib: Fix regression introduced by de6703671386.
This commit is contained in:
parent
e887f3135c
commit
6db1c40b37
1 changed files with 6 additions and 3 deletions
|
@ -128,7 +128,9 @@ def _path_absolute(path):
|
||||||
|
|
||||||
|
|
||||||
def _write_atomic(path, data):
|
def _write_atomic(path, data):
|
||||||
"""Function to write data to a path atomically."""
|
"""Best-effort function to write data to a path atomically.
|
||||||
|
Be prepared to handle a FileExistsError if concurrent writing of the
|
||||||
|
temporary file is attempted."""
|
||||||
# id() is used to generate a pseudo-random filename.
|
# id() is used to generate a pseudo-random filename.
|
||||||
path_tmp = '{}.{}'.format(path, id(path))
|
path_tmp = '{}.{}'.format(path, id(path))
|
||||||
fd = _os.open(path_tmp, _os.O_EXCL | _os.O_CREAT | _os.O_WRONLY, 0o666)
|
fd = _os.open(path_tmp, _os.O_EXCL | _os.O_CREAT | _os.O_WRONLY, 0o666)
|
||||||
|
@ -595,8 +597,9 @@ class _SourceFileLoader(_FileLoader, SourceLoader):
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
_write_atomic(path, data)
|
_write_atomic(path, data)
|
||||||
except PermissionError:
|
except (PermissionError, FileExistsError):
|
||||||
# Don't worry if you can't write bytecode.
|
# Don't worry if you can't write bytecode or someone is writing
|
||||||
|
# it at the same time.
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue