Skip to content

Commit

Permalink
added mutex (#5429)
Browse files Browse the repository at this point in the history
Signed-off-by: joaorufi <[email protected]>
  • Loading branch information
joaorufi authored Jun 8, 2022
1 parent 299d9a7 commit 8455700
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/engine/provider/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"strings"
"sync"

sentryReport "github.com/Checkmarx/kics/internal/sentry"
"github.com/Checkmarx/kics/pkg/model"
Expand All @@ -20,6 +21,7 @@ import (
type FileSystemSourceProvider struct {
paths []string
excludes map[string][]os.FileInfo
mu sync.RWMutex
}

// ErrNotSupportedFile - error representing when a file format is not supported by KICS
Expand Down Expand Up @@ -60,10 +62,12 @@ func (s *FileSystemSourceProvider) AddExcluded(excludePaths []string) error {
}
return errors.Wrap(err, "failed to open excluded file")
}
s.mu.Lock()
if _, ok := s.excludes[info.Name()]; !ok {
s.excludes[info.Name()] = make([]os.FileInfo, 0)
}
s.excludes[info.Name()] = append(s.excludes[info.Name()], info)
s.mu.Unlock()
}
return nil
}
Expand Down Expand Up @@ -196,6 +200,8 @@ func closeFile(file *os.File, info os.FileInfo) {

func (s *FileSystemSourceProvider) checkConditions(info os.FileInfo, extensions model.Extensions,
path string, resolved bool) (bool, error) {
s.mu.RLock()
defer s.mu.RUnlock()
if info.IsDir() {
if f, ok := s.excludes[info.Name()]; ok && containsFile(f, info) {
log.Info().Msgf("Directory ignored: %s", path)
Expand Down

0 comments on commit 8455700

Please sign in to comment.