@@ -81,6 +81,7 @@ class RunCommandOutput(enum.Enum):
81
81
not_applicable_indicator = "N/A"
82
82
relative_size_report_decimal_places = 2
83
83
84
+ temporary_directory = tempfile .TemporaryDirectory (prefix = "compilesketches-" )
84
85
arduino_cli_installation_path = pathlib .Path .home ().joinpath ("bin" )
85
86
arduino_cli_user_directory_path = pathlib .Path .home ().joinpath ("Arduino" )
86
87
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
254
255
"""
255
256
destination_parent_path = pathlib .Path (destination_parent_path )
256
257
257
- # Create temporary folder for the download
258
+ # Create temporary folder with function duration for the download
258
259
with tempfile .TemporaryDirectory ("-compilesketches-download_folder" ) as download_folder :
259
260
download_file_path = pathlib .PurePath (download_folder , url .rsplit (sep = "/" , maxsplit = 1 )[1 ])
260
261
@@ -268,23 +269,24 @@ def install_from_download(self, url, source_path, destination_parent_path, desti
268
269
break
269
270
out_file .write (block )
270
271
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-" )
275
274
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 )
277
277
278
- absolute_source_path = pathlib . Path ( archive_root_path , source_path ). resolve ( )
278
+ archive_root_path = get_archive_root_path ( extract_folder )
279
279
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 ()
283
281
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 )
288
290
289
291
def install_platforms (self ):
290
292
"""Install Arduino boards platforms."""
@@ -537,7 +539,7 @@ def __init__(self):
537
539
return platform_installation_path
538
540
539
541
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.
541
543
542
544
Keyword arguments:
543
545
source_path -- path to install
@@ -563,10 +565,7 @@ def install_from_path(self, source_path, destination_parent_path, destination_na
563
565
# Create the parent path if it doesn't already exist
564
566
destination_parent_path .mkdir (parents = True , exist_ok = True )
565
567
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 ())
570
569
571
570
def install_platforms_from_repository (self , platform_list ):
572
571
"""Install libraries by cloning Git repositories
@@ -628,14 +627,14 @@ def install_from_repository(self,
628
627
# Use the repository name
629
628
destination_name = url .rstrip ("/" ).rsplit (sep = "/" , maxsplit = 1 )[1 ].rsplit (sep = "." , maxsplit = 1 )[0 ]
630
629
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 )
639
638
640
639
def clone_repository (self , url , git_ref , destination_path ):
641
640
"""Clone a Git repository to a specified location and check out the specified ref
0 commit comments