mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.14] gh-141930: Use the regular IO stack to write .pyc files for a better error message on failure (GH-141931) (#142021)
Co-authored-by: Stefano Rivera <stefano@rivera.za.net>
This commit is contained in:
parent
521fb36561
commit
afce34fbf0
3 changed files with 59 additions and 22 deletions
|
|
@ -208,12 +208,8 @@ def _write_atomic(path, data, mode=0o666):
|
|||
try:
|
||||
# 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:
|
||||
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")
|
||||
with _io.open(fd, 'wb') as file:
|
||||
file.write(data)
|
||||
_os.replace(path_tmp, path)
|
||||
except OSError:
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue