1616from datetime import datetime
1717from fosslight_binary import binary_analysis
1818from fosslight_dependency .run_dependency_scanner import run_dependency_scanner
19- from fosslight_util .download import cli_download_and_extract
19+ from fosslight_util .download import cli_download_and_extract , compression_extension
20+ from fosslight_util .download import extract_compressed_file as extract_file
2021from ._get_input import get_input_mode
2122from fosslight_util .set_log import init_log
2223from fosslight_util .timer_thread import TimerThread
@@ -315,6 +316,7 @@ def run_main(mode_list, path_arg, dep_arguments, output_file_or_dir, file_format
315316 default_oss_version = ""
316317 src_path = ""
317318 _executed_path = os .getcwd ()
319+ extract_folder = ""
318320
319321 mode_not_supported = list (set (mode_list ).difference (SCANNER_MODE ))
320322 if mode_not_supported :
@@ -337,6 +339,17 @@ def run_main(mode_list, path_arg, dep_arguments, output_file_or_dir, file_format
337339 if isinstance (path_arg , list ):
338340 if len (path_arg ) == 1 :
339341 src_path = path_arg [0 ]
342+
343+ for ext in compression_extension :
344+ if src_path .endswith (ext ):
345+ temp_folder = f"temp_extract_{ datetime .now ().strftime ('%Y%m%d_%H%M%S' )} "
346+ Path (temp_folder ).mkdir (parents = True , exist_ok = True )
347+
348+ extract_success = extract_file (src_path , temp_folder , False )
349+ if extract_success :
350+ src_path = os .path .join (_executed_path , temp_folder )
351+ extract_folder = src_path
352+ break
340353 else :
341354 logger .warning (f"Cannot analyze with multiple path: { path_arg } " )
342355
@@ -414,6 +427,9 @@ def run_main(mode_list, path_arg, dep_arguments, output_file_or_dir, file_format
414427 output_extension , num_cores , db_url ,
415428 default_oss_name , default_oss_version , url_to_analyze ,
416429 correct_mode , correct_fpath , ui_mode , path_to_exclude )
430+
431+ if extract_folder :
432+ shutil .rmtree (extract_folder )
417433 else :
418434 logger .error ("No mode has been selected for analysis." )
419435 try :
0 commit comments