@@ -81,6 +81,7 @@ class RunCommandOutput(enum.Enum):
8181 not_applicable_indicator = "N/A"
8282 relative_size_report_decimal_places = 2
8383
84+ temporary_directory = tempfile .TemporaryDirectory (prefix = "compilesketches-" )
8485 arduino_cli_installation_path = pathlib .Path .home ().joinpath ("bin" )
8586 arduino_cli_user_directory_path = pathlib .Path .home ().joinpath ("Arduino" )
8687 arduino_cli_data_directory_path = pathlib .Path .home ().joinpath (".arduino15" )
@@ -254,7 +255,7 @@ def install_from_download(self, url, source_path, destination_parent_path, desti
254255 """
255256 destination_parent_path = pathlib .Path (destination_parent_path )
256257
257- # Create temporary folder for the download
258+ # Create temporary folder with function duration for the download
258259 with tempfile .TemporaryDirectory ("-compilesketches-download_folder" ) as download_folder :
259260 download_file_path = pathlib .PurePath (download_folder , url .rsplit (sep = "/" , maxsplit = 1 )[1 ])
260261
@@ -268,23 +269,24 @@ def install_from_download(self, url, source_path, destination_parent_path, desti
268269 break
269270 out_file .write (block )
270271
271- # Create temporary folder for the extraction
272- with tempfile .TemporaryDirectory ("-compilesketches-extract_folder" ) as extract_folder :
273- # Extract archive
274- shutil .unpack_archive (filename = str (download_file_path ), extract_dir = extract_folder )
272+ # Create temporary folder with script run duration for the extraction
273+ extract_folder = tempfile .mkdtemp (dir = self .temporary_directory .name , prefix = "install_from_download-" )
275274
276- archive_root_path = get_archive_root_path (extract_folder )
275+ # Extract archive
276+ shutil .unpack_archive (filename = str (download_file_path ), extract_dir = extract_folder )
277277
278- absolute_source_path = pathlib . Path ( archive_root_path , source_path ). resolve ( )
278+ archive_root_path = get_archive_root_path ( extract_folder )
279279
280- if not absolute_source_path .exists ():
281- print ("::error::Archive source path:" , source_path , "not found" )
282- sys .exit (1 )
280+ absolute_source_path = pathlib .Path (archive_root_path , source_path ).resolve ()
283281
284- self .install_from_path (source_path = absolute_source_path ,
285- destination_parent_path = destination_parent_path ,
286- destination_name = destination_name ,
287- force = force )
282+ if not absolute_source_path .exists ():
283+ print ("::error::Archive source path:" , source_path , "not found" )
284+ sys .exit (1 )
285+
286+ self .install_from_path (source_path = absolute_source_path ,
287+ destination_parent_path = destination_parent_path ,
288+ destination_name = destination_name ,
289+ force = force )
288290
289291 def install_platforms (self ):
290292 """Install Arduino boards platforms."""
@@ -537,7 +539,7 @@ def __init__(self):
537539 return platform_installation_path
538540
539541 def install_from_path (self , source_path , destination_parent_path , destination_name = None , force = False ):
540- """Copy the source path to the destination path.
542+ """Create a symlink to the source path in the destination path.
541543
542544 Keyword arguments:
543545 source_path -- path to install
@@ -563,10 +565,7 @@ def install_from_path(self, source_path, destination_parent_path, destination_na
563565 # Create the parent path if it doesn't already exist
564566 destination_parent_path .mkdir (parents = True , exist_ok = True )
565567
566- if source_path .is_dir ():
567- shutil .copytree (src = source_path , dst = destination_path )
568- else :
569- shutil .copy (src = source_path , dst = destination_path )
568+ destination_path .symlink_to (target = source_path , target_is_directory = source_path .is_dir ())
570569
571570 def install_platforms_from_repository (self , platform_list ):
572571 """Install libraries by cloning Git repositories
@@ -628,14 +627,14 @@ def install_from_repository(self,
628627 # Use the repository name
629628 destination_name = url .rstrip ("/" ).rsplit (sep = "/" , maxsplit = 1 )[1 ].rsplit (sep = "." , maxsplit = 1 )[0 ]
630629
631- # Clone to a temporary folder to allow installing from subfolders of repos
632- with tempfile .TemporaryDirectory () as clone_folder :
633- self .clone_repository (url = url , git_ref = git_ref , destination_path = clone_folder )
634- # Install to the final location
635- self .install_from_path (source_path = pathlib .Path (clone_folder , source_path ),
636- destination_parent_path = destination_parent_path ,
637- destination_name = destination_name ,
638- force = force )
630+ # Clone to a temporary folder with script run duration to allow installing from subfolders of repos
631+ clone_folder = tempfile .mkdtemp ( dir = self . temporary_directory . name , prefix = "install_from_repository-" )
632+ self .clone_repository (url = url , git_ref = git_ref , destination_path = clone_folder )
633+ # Install to the final location
634+ self .install_from_path (source_path = pathlib .Path (clone_folder , source_path ),
635+ destination_parent_path = destination_parent_path ,
636+ destination_name = destination_name ,
637+ force = force )
639638
640639 def clone_repository (self , url , git_ref , destination_path ):
641640 """Clone a Git repository to a specified location and check out the specified ref
0 commit comments