diff --git a/src/fosslight_source/cli.py b/src/fosslight_source/cli.py index 909779c..e18254c 100755 --- a/src/fosslight_source/cli.py +++ b/src/fosslight_source/cli.py @@ -8,6 +8,7 @@ import platform import warnings import logging +import fnmatch from datetime import datetime import fosslight_util.constant as constant from fosslight_util.set_log import init_log @@ -285,14 +286,15 @@ def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_do for i in range(len(scancode_result) - 1, -1, -1): item = scancode_result[i] item_path = item.source_name_or_path + + # normalize for windows + normalized_patterns = [os.path.normpath(pattern).replace("\\", "/") for pattern in path_to_exclude] - if not any( - item_path == excluded or item_path.startswith(f"{excluded}{os.sep}") - for excluded in path_to_exclude - ): - item.set_oss_item() - else: + # remove from the scanned list if path is matched with exclude patterns + if any(fnmatch.fnmatch(item_path.replace("\\", "/"), pattern) for pattern in normalized_patterns): del scancode_result[i] + else: + item.set_oss_item() return scancode_result @@ -345,7 +347,7 @@ def run_scanners( success, result_log[RESULT_KEY], scancode_result, license_list = run_scan(path_to_scan, output_file_name, write_json_file, num_cores, True, print_matched_text, formats, called_by_cli, - time_out, correct_mode, correct_filepath) + time_out, correct_mode, correct_filepath, path_to_exclude) if selected_scanner == 'scanoss' or selected_scanner == 'all' or selected_scanner == '': scanoss_result = run_scanoss_py(path_to_scan, output_file_name, formats, True, write_json_file, num_cores, path_to_exclude)