Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/engine/provider/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type FileSystemSourceProvider struct {

var (
queryRegexExcludeTerraCache = regexp.MustCompile(fmt.Sprintf(`^(.*?%s)?\.terra.*`, regexp.QuoteMeta(string(os.PathSeparator))))
queryRegexExcludeCacheFile = regexp.MustCompile(`^.*\.cache\..+$`)
// ErrNotSupportedFile - error representing when a file format is not supported by KICS
ErrNotSupportedFile = errors.New("invalid file format")
)
Expand Down Expand Up @@ -260,6 +261,11 @@ func (s *FileSystemSourceProvider) checkConditions(info os.FileInfo, extensions
log.Trace().Msgf("File ignored: %s", path)
return true, nil
}
// exclude cache files
if queryRegexExcludeCacheFile.MatchString(info.Name()) {
log.Trace().Msgf("File ignored: %s", path)
return true, nil
}
ext, _ := utils.GetExtension(path)
if !extensions.Include(ext) {
log.Trace().Msgf("File ignored: %s", path)
Expand Down
20 changes: 20 additions & 0 deletions pkg/engine/provider/filesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ func TestFileSystemSourceProvider_checkConditions(t *testing.T) {
checkStatErr(t, errTerraCache)
infoTerraCacheFolder, errTerraCacheFolder := os.Stat(filepath.FromSlash("test/fixtures/test_terra_cache/.terraform"))
checkStatErr(t, errTerraCacheFolder)
infoCacheFile, errCacheFile := os.Stat(filepath.FromSlash("test/fixtures/test_cache_file/test.cache.tf"))
checkStatErr(t, errCacheFile)

type fields struct {
paths []string
Expand Down Expand Up @@ -597,6 +599,24 @@ func TestFileSystemSourceProvider_checkConditions(t *testing.T) {
err: filepath.SkipDir,
},
},
{
name: "check_condition_ignore_cache_file for file matching *.cache.* pattern",
fields: fields{
paths: []string{filepath.FromSlash("test/fixtures/test_cache_file/test.cache.tf")},
excludes: nil,
},
args: args{
info: infoCacheFile,
extensions: model.Extensions{
".tf": dockerParser.Parser{},
},
path: filepath.FromSlash("test/fixtures/test_cache_file/test.cache.tf"),
},
want: want{
got: true,
err: nil,
},
},
{
name: "should_skip_terra_cache_folder",
fields: fields{
Expand Down
Empty file.
Loading