Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/fosslight_binary/binary_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from io import open
import subprocess
import re
import shutil

PKG_NAME = "fosslight_binary"
logger = logging.getLogger(constant.LOGGER_NAME)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -115,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)
Expand All @@ -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):
Expand Down Expand Up @@ -177,11 +181,10 @@ 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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bjk7119
이렇게되면 기존 output_path가 .fosslight_tmp로 변경되는데 로그말고 영향끼치는 부분 없나요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 로그 말고는 결과파일 생성도 동일하게 되고 영향 끼치는 부분이 없으나
로그에도 original_output_path가 찍히는게 맞을 것 같아 추가 수정하였습니다.

path_to_find_bin, output_dir, formats, path_to_exclude)

total_bin_cnt = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bjk7119
더이상 안쓰는 변수 정리해주세요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return 받는 변수 모두 사용됩니다.
아래 total_file_cnt는 사용되지 않아 제거하였습니다.

total_file_cnt = 0
db_loaded_cnt = 0
success_to_write = False
writing_msg = ""
Expand All @@ -204,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}",
Expand Down Expand Up @@ -273,9 +276,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:
Expand Down Expand Up @@ -397,7 +406,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
Expand Down