11import os
2- from typing import TYPE_CHECKING , Iterable , List , Tuple
3-
4- import pathspec
2+ from typing import TYPE_CHECKING , List , Tuple
53
64from cycode .cli .files_collector .excluder import exclude_irrelevant_files
75from cycode .cli .files_collector .iac .tf_content_generator import (
108 is_iac ,
119 is_tfplan_file ,
1210)
11+ from cycode .cli .files_collector .walk_ignore import walk_ignore
1312from cycode .cli .models import Document
1413from cycode .cli .utils .path_utils import get_absolute_path , get_file_content
1514from cycode .cyclient import logger
1817 from cycode .cli .utils .progress_bar import BaseProgressBar , ProgressBarSection
1918
2019
21- def _get_all_existing_files_in_directory (path : str ) -> List [str ]:
20+ def _get_all_existing_files_in_directory (path : str , * , walk_with_ignore_patterns : bool = True ) -> List [str ]:
2221 files : List [str ] = []
2322
24- for root , _ , filenames in os .walk (path ):
23+ walk_func = walk_ignore if walk_with_ignore_patterns else os .walk
24+ for root , _ , filenames in walk_func (path ):
2525 for filename in filenames :
2626 files .append (os .path .join (root , filename ))
2727
2828 return files
2929
3030
31- def _get_relevant_files_in_path (path : str , exclude_patterns : Iterable [ str ] ) -> List [str ]:
31+ def _get_relevant_files_in_path (path : str ) -> List [str ]:
3232 absolute_path = get_absolute_path (path )
3333
3434 if not os .path .isfile (absolute_path ) and not os .path .isdir (absolute_path ):
@@ -37,24 +37,16 @@ def _get_relevant_files_in_path(path: str, exclude_patterns: Iterable[str]) -> L
3737 if os .path .isfile (absolute_path ):
3838 return [absolute_path ]
3939
40- all_file_paths = set (_get_all_existing_files_in_directory (absolute_path ))
41-
42- path_spec = pathspec .PathSpec .from_lines (pathspec .patterns .GitWildMatchPattern , exclude_patterns )
43- excluded_file_paths = set (path_spec .match_files (all_file_paths ))
44-
45- relevant_file_paths = all_file_paths - excluded_file_paths
46-
47- return [file_path for file_path in relevant_file_paths if os .path .isfile (file_path )]
40+ file_paths = _get_all_existing_files_in_directory (absolute_path )
41+ return [file_path for file_path in file_paths if os .path .isfile (file_path )]
4842
4943
5044def _get_relevant_files (
5145 progress_bar : 'BaseProgressBar' , progress_bar_section : 'ProgressBarSection' , scan_type : str , paths : Tuple [str ]
5246) -> List [str ]:
5347 all_files_to_scan = []
5448 for path in paths :
55- all_files_to_scan .extend (
56- _get_relevant_files_in_path (path = path , exclude_patterns = ['**/.git/**' , '**/.cycode/**' ])
57- )
49+ all_files_to_scan .extend (_get_relevant_files_in_path (path ))
5850
5951 # we are double the progress bar section length because we are going to process the files twice
6052 # first time to get the file list with respect of excluded patterns (excluding takes seconds to execute)
0 commit comments