mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
GH-126606: don't write incomplete pyc files (GH-126627)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru> Co-authored-by: Brett Cannon <brett@python.org>
This commit is contained in:
parent
f6b0361c17
commit
c695e37a3f
3 changed files with 40 additions and 1 deletions
|
@ -209,7 +209,11 @@ def _write_atomic(path, data, mode=0o666):
|
|||
# We first write data to a temporary file, and then use os.replace() to
|
||||
# perform an atomic rename.
|
||||
with _io.FileIO(fd, 'wb') as file:
|
||||
file.write(data)
|
||||
bytes_written = file.write(data)
|
||||
if bytes_written != len(data):
|
||||
# Raise an OSError so the 'except' below cleans up the partially
|
||||
# written file.
|
||||
raise OSError("os.write() didn't write the full pyc file")
|
||||
_os.replace(path_tmp, path)
|
||||
except OSError:
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue