aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/importlib/_bootstrap_external.py
diff options
context:
space:
mode:
authorCF Bolz-Tereick <cfbolz@gmx.de>2024-11-13 22:39:10 +0100
committerGitHub <noreply@github.com>2024-11-13 21:39:10 +0000
commitc695e37a3f95c225ee08d1e882d23fa200b5ec34 (patch)
treee6fa1a1d16ddbf14862c5eaf3009fdba25a2b1d8 /Lib/importlib/_bootstrap_external.py
parentf6b0361c17552197f44be16435e4a5cb4b1d60ca (diff)
downloadcpython-c695e37a3f95c225ee08d1e882d23fa200b5ec34.tar.gz
cpython-c695e37a3f95c225ee08d1e882d23fa200b5ec34.zip
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>
Diffstat (limited to 'Lib/importlib/_bootstrap_external.py')
-rw-r--r--Lib/importlib/_bootstrap_external.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index 1b76328429f..fa361597118 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -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: