Skip to content

Commit d023f52

Browse files
authored
Merge pull request #153 from fosslight/package_exlcude
Exclude package dirs with directory name
2 parents 5362cf9 + 8a5aaff commit d023f52

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

src/fosslight_binary/_binary.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
# -*- coding: utf-8 -*-
33
# Copyright (c) 2020 LG Electronics Inc.
44
# SPDX-License-Identifier: Apache-2.0
5-
from fosslight_util.oss_item import FileItem
5+
import os
66
import urllib.parse
77
import logging
88
import fosslight_util.constant as constant
9+
from typing import Tuple
10+
from fosslight_util.oss_item import FileItem
911

1012
EXCLUDE_TRUE_VALUE = "Exclude"
1113
TLSH_CHECKSUM_NULL = "0"
1214
MAX_EXCEL_URL_LENGTH = 255
1315
EXCEEDED_VUL_URL_LENGTH_COMMENT = f"Exceeded the maximum vulnerability URL length of {MAX_EXCEL_URL_LENGTH} characters."
16+
_PACKAGE_DIR = ["node_modules", "venv", "Pods", "Carthage"]
1417

1518
logger = logging.getLogger(constant.LOGGER_NAME)
1619

@@ -108,3 +111,15 @@ def get_print_json(self):
108111
if self.comment:
109112
json_item["comment"] = self.comment
110113
return items
114+
115+
116+
def is_package_dir(bin_with_path: str, _root_path: str) -> Tuple[bool, str]:
117+
is_pkg = False
118+
pkg_path = ""
119+
path_parts = bin_with_path.split(os.path.sep)
120+
for pkg_dir in _PACKAGE_DIR:
121+
if pkg_dir in path_parts:
122+
pkg_index = path_parts.index(pkg_dir)
123+
pkg_path = os.path.sep.join(path_parts[:pkg_index + 1]).replace(_root_path, '', 1)
124+
is_pkg = True
125+
return is_pkg, pkg_path

src/fosslight_binary/_jar_analysis.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import os
99
import sys
1010
import fosslight_util.constant as constant
11-
from ._binary import BinaryItem, VulnerabilityItem
11+
from ._binary import BinaryItem, VulnerabilityItem, is_package_dir
1212
from fosslight_util.oss_item import OssItem
1313
from dependency_check import run as dependency_check_run
1414

@@ -87,6 +87,11 @@ def merge_binary_list(owasp_items, vulnerability_items, bin_list):
8787
bin_item = BinaryItem(os.path.abspath(key))
8888
bin_item.binary_name_without_path = os.path.basename(key)
8989
bin_item.source_name_or_path = key
90+
91+
is_pkg, _ = is_package_dir(bin_item.source_name_or_path, '')
92+
if is_pkg:
93+
continue
94+
9095
bin_item.set_oss_items(oss_list)
9196
not_found_bin.append(bin_item)
9297

src/fosslight_binary/binary_analysis.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import fosslight_util.constant as constant
1717
from fosslight_util.output_format import check_output_formats_v2, write_output_file
1818
from ._binary_dao import get_oss_info_from_db
19-
from ._binary import BinaryItem, TLSH_CHECKSUM_NULL
19+
from ._binary import BinaryItem, TLSH_CHECKSUM_NULL, is_package_dir
2020
from ._jar_analysis import analyze_jar_file, merge_binary_list
2121
from ._simple_mode import print_simple_mode, filter_binary, init_simple
2222
from fosslight_util.correct import correct_with_yaml
@@ -165,8 +165,15 @@ def get_file_list(path_to_find, abs_path_to_exclude):
165165
bin_with_path = os.path.join(root, file)
166166
bin_item = BinaryItem(bin_with_path)
167167
bin_item.binary_name_without_path = file
168-
bin_item.source_name_or_path = bin_with_path.replace(
169-
_root_path, '', 1)
168+
bin_item.source_name_or_path = bin_with_path.replace(_root_path, '', 1)
169+
170+
is_pkg, pkg_path = is_package_dir(bin_with_path, _root_path)
171+
if is_pkg:
172+
bin_item.source_name_or_path = pkg_path
173+
if not any(x.source_name_or_path == bin_item.source_name_or_path for x in bin_list):
174+
bin_item.exclude = True
175+
bin_list.append(bin_item)
176+
continue
170177

171178
if any(dir_name in dir_path for dir_name in _EXCLUDE_DIR):
172179
bin_item.exclude = True

0 commit comments

Comments
 (0)