Skip to content

Commit 31cab20

Browse files
authored
Fix installing an installed running process (#941)
1 parent 433504f commit 31cab20

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pkg/private/install.py.tpl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import os
2323
import pathlib
2424
import shutil
2525
import sys
26+
import tempfile
2627

2728
from pkg.private import manifest
2829

@@ -79,7 +80,19 @@ class NativeInstaller(object):
7980

8081
def _do_file_copy(self, src, dest):
8182
logging.debug("COPY %s <- %s", dest, src)
82-
shutil.copyfile(src, dest)
83+
# Copy to a temporary file and then move it to the destination.
84+
# This ensures code-signed executables on certain platforms
85+
# behave correctly.
86+
# See: https://developer.apple.com/documentation/security/updating-mac-software
87+
# Use `dir` to ensure the temporary file is created on the same file system as the destination,
88+
# to avoid cross-filesystem replace which is an error on some platforms.
89+
with tempfile.NamedTemporaryFile(delete=False, dir=os.path.dirname(dest)) as tmp_file:
90+
try:
91+
shutil.copyfile(src, tmp_file.name)
92+
os.replace(tmp_file.name, dest)
93+
except:
94+
pathlib.Path(tmp_file.name).unlink(missing_ok=True)
95+
raise
8396

8497
def _do_mkdir(self, dirname, mode):
8598
logging.debug("MKDIR %s %s", mode, dirname)

0 commit comments

Comments
 (0)