Skip to content

Commit 15cae7e

Browse files
committed
Prevent issues with rebuilding interpreter on a different drive from the temp folder.
1 parent 6c5239a commit 15cae7e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Lib/rebuildpython.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import sys
1616
import sysconfig
1717
import tempfile
18+
import uuid
1819

1920
MOVEFILE_DELAY_UNTIL_REBOOT = 4
2021

@@ -472,8 +473,12 @@ def run_rebuild():
472473
tmp = tempfile.NamedTemporaryFile(delete=False)
473474
tmp.close()
474475
os.unlink(tmp.name)
475-
shutil.move(sys.executable, tmp.name)
476-
ctypes.windll.kernel32.MoveFileExW(tmp.name, None, MOVEFILE_DELAY_UNTIL_REBOOT)
476+
temp_path = tmp.name
477+
if os.path.splitdrive(temp_path)[0] == os.path.splitdrive(sys.executable)[0]:
478+
shutil.move(sys.executable, temp_path)
479+
else:
480+
shutil.move(sys.executable, sys.executable + uuid.uuid4().hex + ".old")
481+
ctypes.windll.kernel32.MoveFileExW(temp_path, None, MOVEFILE_DELAY_UNTIL_REBOOT)
477482

478483
shutil.move(os.path.join(build_dir, "python.exe"), interpreter_path)
479484
elif platform.system() == "Linux":

0 commit comments

Comments
 (0)