From 0c345521e32f728ddc66e1a0dbd2d4755559a67e Mon Sep 17 00:00:00 2001 From: Jaekwon Bang Date: Fri, 23 Jan 2026 17:26:45 +0900 Subject: [PATCH 1/2] Use hidden dir for intermeditate to fix scan count --- src/fosslight_binary/binary_analysis.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/fosslight_binary/binary_analysis.py b/src/fosslight_binary/binary_analysis.py index ccb73fe..1dda702 100755 --- a/src/fosslight_binary/binary_analysis.py +++ b/src/fosslight_binary/binary_analysis.py @@ -27,6 +27,7 @@ from io import open import subprocess import re +import shutil PKG_NAME = "fosslight_binary" logger = logging.getLogger(constant.LOGGER_NAME) @@ -82,6 +83,9 @@ def init(path_to_find_bin, output_file_name, formats, path_to_exclude=[]): else: output_path = os.path.abspath(output_path) + original_output_path = output_path + output_path = os.path.join(output_path, '.fosslight_temp') + while len(output_files) < len(output_extensions): output_files.append(None) to_remove = [] # elements of spdx format on windows that should be removed @@ -128,7 +132,7 @@ def init(path_to_find_bin, output_file_name, formats, path_to_exclude=[]): error_occured(error_msg=msg, result_log=_result_log, exit=True) - return _result_log, combined_paths_and_files, output_extensions, formats + return _result_log, combined_paths_and_files, output_extensions, formats, output_path, original_output_path def get_file_list(path_to_find, excluded_files): @@ -177,7 +181,7 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F mode = "Simple Mode" _result_log, compressed_list_txt, simple_bin_list_txt = init_simple(output_dir, PKG_NAME, start_time) else: - _result_log, result_reports, output_extensions, formats = init( + _result_log, result_reports, output_extensions, formats, output_path, original_output_path = init( path_to_find_bin, output_dir, formats, path_to_exclude) total_bin_cnt = 0 @@ -273,9 +277,15 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F else: logger.error(f"Fail to generate result file.:{writing_msg}") + try: + shutil.copytree(output_path, original_output_path, dirs_exist_ok=True) + shutil.rmtree(output_path) + except Exception as ex: + logger.debug(f"Failed to move temp files: {ex}") + try: print_result_log(mode=mode, success=True, result_log=_result_log, - file_cnt=str(total_file_cnt), + file_cnt=str(cnt_file_except_skipped), bin_file_cnt=str(total_bin_cnt), auto_bin_cnt=str(db_loaded_cnt), bin_list=bin_list) except Exception as ex: @@ -397,7 +407,6 @@ def print_result_log(mode="Normal Mode", success=True, result_log={}, file_cnt=" result_log["Running time"] = starttime + " ~ " + \ datetime.now().strftime('%Y%m%d_%H%M%S') result_log["Execution result"] = 'Success' if success else 'Error occurred' - result_log["Binaries / Scanned files"] = f"{bin_file_cnt}/{file_cnt}" result_log["Identified in Binary DB / Binaries"] = f"{auto_bin_cnt}/{bin_file_cnt}" if len(_error_logs) > 0: result_log["Error Log"] = _error_logs From 23f4e817cb748e30cd8d8eb9bcb7339b353e076c Mon Sep 17 00:00:00 2001 From: Jaekwon Bang Date: Sat, 24 Jan 2026 22:41:13 +0900 Subject: [PATCH 2/2] Print orignal path for logging --- src/fosslight_binary/binary_analysis.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/fosslight_binary/binary_analysis.py b/src/fosslight_binary/binary_analysis.py index 1dda702..6f2f303 100755 --- a/src/fosslight_binary/binary_analysis.py +++ b/src/fosslight_binary/binary_analysis.py @@ -119,7 +119,7 @@ def init(path_to_find_bin, output_file_name, formats, path_to_exclude=[]): if len(output_extensions) < 1: sys.exit(0) - combined_paths_and_files = [os.path.join(output_path, file) for file in output_files] + combined_paths_and_files = [os.path.join(original_output_path, file) for file in output_files] else: logger.error(f"Format error - {msg}") sys.exit(1) @@ -185,7 +185,6 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F path_to_find_bin, output_dir, formats, path_to_exclude) total_bin_cnt = 0 - total_file_cnt = 0 db_loaded_cnt = 0 success_to_write = False writing_msg = "" @@ -208,7 +207,7 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F if not correct_filepath: correct_filepath = path_to_find_bin try: - total_file_cnt, file_list, found_jar = get_file_list(path_to_find_bin, excluded_files) + _, file_list, found_jar = get_file_list(path_to_find_bin, excluded_files) return_list = list(return_bin_only(file_list)) except Exception as ex: error_occured(error_msg=f"Failed to check whether it is binary or not : {ex}",