From 1c9c88f0645ffdac6e5182d813b4d23e8928ea3e Mon Sep 17 00:00:00 2001 From: alex-cheng-techman Date: Fri, 20 Jun 2025 15:21:40 +0800 Subject: [PATCH 1/3] Fix: reinstate exclude logic for checkers --- cve_bin_tool/util.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cve_bin_tool/util.py b/cve_bin_tool/util.py index 11ee0533f4..867b06932a 100644 --- a/cve_bin_tool/util.py +++ b/cve_bin_tool/util.py @@ -534,14 +534,15 @@ def walk(self, roots: list[str] | None = None) -> Iterator[str]: filenames.remove(filename) except PermissionError: filenames.remove(filename) + dirnames[:] = [ dirname for dirname in dirnames if self.pattern_match( - str(Path(dirpath) / dirname), self.folder_include_pattern + os.path.join(dirpath, dirname), self.folder_include_pattern ) and not self.pattern_match( - str(Path(dirpath) / dirname), self.folder_exclude_pattern + os.path.join(dirpath, dirname), self.folder_exclude_pattern ) ] # Yields From 94aebc47c844e3c105135cb599ae7624373fd4af Mon Sep 17 00:00:00 2001 From: alex-cheng-techman Date: Tue, 24 Jun 2025 14:20:17 +0800 Subject: [PATCH 2/3] using pathlib instead of os.path --- cve_bin_tool/util.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cve_bin_tool/util.py b/cve_bin_tool/util.py index 867b06932a..3b02e9feb0 100644 --- a/cve_bin_tool/util.py +++ b/cve_bin_tool/util.py @@ -538,12 +538,12 @@ def walk(self, roots: list[str] | None = None) -> Iterator[str]: dirnames[:] = [ dirname for dirname in dirnames - if self.pattern_match( - os.path.join(dirpath, dirname), self.folder_include_pattern - ) - and not self.pattern_match( - os.path.join(dirpath, dirname), self.folder_exclude_pattern - ) + if self.pattern_match( + str(Path(dirpath) / dirname), self.folder_include_pattern + ) + and not self.pattern_match( + str(Path(dirpath) / dirname), self.folder_exclude_pattern + ) ] # Yields if self.yield_files: @@ -559,7 +559,7 @@ def pattern_match(text: str, patterns: str) -> bool: if not patterns: return False for pattern in patterns.split(";"): - if fnmatch.fnmatch(text, pattern): + if fnmatch.fnmatch(str(Path(text).absolute()), str(Path(pattern).absolute())): return True return False From 94933846249b631b547953addf47f936a41f187a Mon Sep 17 00:00:00 2001 From: alex-cheng-techman Date: Wed, 25 Jun 2025 16:41:51 +0800 Subject: [PATCH 3/3] fix: restore --exclude directory filtering logic --- cve_bin_tool/util.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/cve_bin_tool/util.py b/cve_bin_tool/util.py index 3b02e9feb0..cf745cc493 100644 --- a/cve_bin_tool/util.py +++ b/cve_bin_tool/util.py @@ -534,16 +534,16 @@ def walk(self, roots: list[str] | None = None) -> Iterator[str]: filenames.remove(filename) except PermissionError: filenames.remove(filename) - + dirnames[:] = [ dirname for dirname in dirnames - if self.pattern_match( - str(Path(dirpath) / dirname), self.folder_include_pattern - ) - and not self.pattern_match( - str(Path(dirpath) / dirname), self.folder_exclude_pattern - ) + if self.pattern_match( + str(Path(dirpath) / dirname), self.folder_include_pattern + ) + and not self.pattern_match( + str(Path(dirpath) / dirname), self.folder_exclude_pattern + ) ] # Yields if self.yield_files: @@ -559,7 +559,9 @@ def pattern_match(text: str, patterns: str) -> bool: if not patterns: return False for pattern in patterns.split(";"): - if fnmatch.fnmatch(str(Path(text).absolute()), str(Path(pattern).absolute())): + if fnmatch.fnmatch( + str(Path(text).absolute()), str(Path(pattern).absolute()) + ): return True return False