File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import os
2323import pathlib
2424import shutil
2525import sys
26+ import tempfile
2627
2728from 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 )
You can’t perform that action at this time.
0 commit comments