Skip to content

Commit 56a7921

Browse files
Fix exclude error
Signed-off-by: Wonjae Park <[email protected]>
1 parent 9d38ef5 commit 56a7921

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/fosslight_source/cli.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import fosslight_util.constant as constant
1313
from fosslight_util.set_log import init_log
1414
from fosslight_util.timer_thread import TimerThread
15+
from fosslight_util.exclude import excluding_files
1516
from ._help import print_version, print_help_msg_source_scanner
1617
from ._license_matched import get_license_list_to_print
1718
from fosslight_util.output_format import check_output_formats_v2, write_output_file
@@ -261,7 +262,8 @@ def create_report_file(
261262
return scan_item
262263

263264

264-
def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_downloads: dict = {}) -> list:
265+
def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_downloads: dict = {}, excluded_file_list=[]) -> list:
266+
265267
"""
266268
Merge scanner results and spdx parsing result.
267269
:param scancode_result: list of scancode results in SourceItem.
@@ -285,6 +287,11 @@ def merge_results(scancode_result: list = [], scanoss_result: list = [], spdx_do
285287
new_result_item.download_location = download_location
286288
scancode_result.append(new_result_item)
287289

290+
for i in range(len(scancode_result) - 1, -1, -1): # Iterate from last to first
291+
item_path = scancode_result[i].source_name_or_path # Assuming SourceItem has 'file_path' attribute
292+
if item_path in excluded_file_list:
293+
del scancode_result[i] # Delete matching item
294+
288295
for item in scancode_result:
289296
item.set_oss_item()
290297

@@ -329,6 +336,7 @@ def run_scanners(
329336

330337
logger, result_log = init_log(os.path.join(output_path, f"fosslight_log_src_{start_time}.txt"),
331338
True, logging.INFO, logging.DEBUG, PKG_NAME, path_to_scan, path_to_exclude)
339+
excluded_file_list = excluding_files(path_to_exclude, path_to_scan)
332340

333341
if '.xlsx' not in output_extensions and print_matched_text:
334342
logger.warning("-m option is only available for excel.")
@@ -345,7 +353,7 @@ def run_scanners(
345353
path_to_exclude)
346354
if selected_scanner in SCANNER_TYPE:
347355
spdx_downloads = get_spdx_downloads(path_to_scan, path_to_exclude)
348-
merged_result = merge_results(scancode_result, scanoss_result, spdx_downloads)
356+
merged_result = merge_results(scancode_result, scanoss_result, spdx_downloads, excluded_file_list)
349357
scan_item = create_report_file(start_time, merged_result, license_list, scanoss_result, selected_scanner,
350358
print_matched_text, output_path, output_files, output_extensions, correct_mode,
351359
correct_filepath, path_to_scan, path_to_exclude, formats)

0 commit comments

Comments
 (0)