@@ -78,7 +78,8 @@ class Scanner:
7878 def __init__ (self , wfp : str = None , scan_output : str = None , output_format : str = 'plain' ,
7979 debug : bool = False , trace : bool = False , quiet : bool = False , api_key : str = None , url : str = None ,
8080 sbom_path : str = None , scan_type : str = None , flags : str = None , nb_threads : int = 5 ,
81- skip_snippets : bool = False , post_size : int = 64 , timeout : int = 120 , no_wfp_file : bool = False
81+ skip_snippets : bool = False , post_size : int = 64 , timeout : int = 120 , no_wfp_file : bool = False ,
82+ all_extensions : bool = False , all_folders : bool = False , hidden_files_folders : bool = False
8283 ):
8384 """
8485 Initialise scanning class, including Winnowing, ScanossApi and ThreadedScanning
@@ -91,7 +92,10 @@ def __init__(self, wfp: str = None, scan_output: str = None, output_format: str
9192 self .output_format = output_format
9293 self .no_wfp_file = no_wfp_file
9394 self .isatty = sys .stderr .isatty ()
94- self .winnowing = Winnowing (debug = debug , quiet = quiet , skip_snippets = skip_snippets )
95+ self .all_extensions = all_extensions
96+ self .all_folders = all_folders
97+ self .hidden_files_folders = hidden_files_folders
98+ self .winnowing = Winnowing (debug = debug , quiet = quiet , skip_snippets = skip_snippets , all_extensions = all_extensions )
9599 self .scanoss_api = ScanossApi (debug = debug , trace = trace , quiet = quiet , api_key = api_key , url = url ,
96100 sbom_path = sbom_path , scan_type = scan_type , flags = flags , timeout = timeout
97101 )
@@ -106,8 +110,7 @@ def __init__(self, wfp: str = None, scan_output: str = None, output_format: str
106110 if skip_snippets :
107111 self .max_post_size = 8 * 1024 # 8k Max post size if we're skipping snippets
108112
109- @staticmethod
110- def __filter_files (files ) -> list :
113+ def __filter_files (self , files : list ) -> list :
111114 """
112115 Filter which files should be considered for processing
113116 :param files: list of files to filter
@@ -116,23 +119,22 @@ def __filter_files(files) -> list:
116119 file_list = []
117120 for f in files :
118121 ignore = False
119- if f .startswith ("." ): # Ignore all . files
122+ if f .startswith ("." ) and not self . hidden_files_folders : # Ignore all . files unless requested
120123 ignore = True
121- if not ignore :
124+ if not ignore and not self . all_extensions : # Skip this check if we're allowing all extensions
122125 f_lower = f .lower ()
123- if f_lower in FILTERED_FILES : # Check for exact files to ignore
126+ if f_lower in FILTERED_FILES : # Check for exact files to ignore
124127 ignore = True
125128 if not ignore :
126- for ending in FILTERED_EXT : # Check for file endings to ignore
129+ for ending in FILTERED_EXT : # Check for file endings to ignore
127130 if f_lower .endswith (ending ):
128131 ignore = True
129132 break
130133 if not ignore :
131134 file_list .append (f )
132135 return file_list
133136
134- @staticmethod
135- def __filter_dirs (dirs : list ) -> list :
137+ def __filter_dirs (self , dirs : list ) -> list :
136138 """
137139 Filter which folders should be considered for processing
138140 :param dirs: list of directories to filter
@@ -141,9 +143,9 @@ def __filter_dirs(dirs: list) -> list:
141143 dir_list = []
142144 for d in dirs :
143145 ignore = False
144- if d .startswith ("." ): # Ignore all . folders
146+ if d .startswith ("." ) and not self . hidden_files_folders : # Ignore all . folders unless requested
145147 ignore = True
146- if not ignore :
148+ if not ignore and not self . all_folders : # Skip this check if we're allowing all folders
147149 d_lower = d .lower ()
148150 if d_lower in FILTERED_DIRS : # Ignore specific folders
149151 ignore = True
@@ -278,8 +280,8 @@ def scan_folder(self, scan_dir: str) -> bool:
278280 scan_started = False
279281 for root , dirs , files in os .walk (scan_dir ):
280282 self .print_trace (f'U Root: { root } , Dirs: { dirs } , Files { files } ' )
281- dirs [:] = Scanner .__filter_dirs (dirs ) # Strip out unwanted directories
282- filtered_files = Scanner .__filter_files (files ) # Strip out unwanted files
283+ dirs [:] = self .__filter_dirs (dirs ) # Strip out unwanted directories
284+ filtered_files = self .__filter_files (files ) # Strip out unwanted files
283285 self .print_debug (f'F Root: { root } , Dirs: { dirs } , Files { filtered_files } ' )
284286 for file in filtered_files : # Cycle through each filtered file
285287 path = os .path .join (root , file )
@@ -624,8 +626,8 @@ def wfp_folder(self, scan_dir: str, wfp_file: str = None):
624626 scan_dir_len = len (scan_dir ) if scan_dir .endswith (os .path .sep ) else len (scan_dir )+ 1
625627 self .print_msg (f'Searching { scan_dir } for files to fingerprint...' )
626628 for root , dirs , files in os .walk (scan_dir ):
627- dirs [:] = Scanner .__filter_dirs (dirs ) # Strip out unwanted directories
628- filtered_files = Scanner .__filter_files (files ) # Strip out unwanted files
629+ dirs [:] = self .__filter_dirs (dirs ) # Strip out unwanted directories
630+ filtered_files = self .__filter_files (files ) # Strip out unwanted files
629631 self .print_trace (f'Root: { root } , Dirs: { dirs } , Files { filtered_files } ' )
630632 for file in filtered_files :
631633 path = os .path .join (root , file )
0 commit comments