-
Notifications
You must be signed in to change notification settings - Fork 4
Use hidden dir for intermeditate to fix scan count #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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) | ||
|
|
@@ -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,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( | ||
| path_to_find_bin, output_dir, formats, path_to_exclude) | ||
|
|
||
| total_bin_cnt = 0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bjk7119
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return 받는 변수 모두 사용됩니다. |
||
| total_file_cnt = 0 | ||
| db_loaded_cnt = 0 | ||
| success_to_write = False | ||
| writing_msg = "" | ||
|
|
@@ -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}", | ||
|
|
@@ -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: | ||
|
|
@@ -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 | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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로 변경되는데 로그말고 영향끼치는 부분 없나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네 로그 말고는 결과파일 생성도 동일하게 되고 영향 끼치는 부분이 없으나
로그에도 original_output_path가 찍히는게 맞을 것 같아 추가 수정하였습니다.