diff --git a/pkg/parser/parser.go b/pkg/parser/parser.go index f3ca1ab4..5b0896b0 100644 --- a/pkg/parser/parser.go +++ b/pkg/parser/parser.go @@ -64,11 +64,20 @@ func (p *Parser) processViolations(paths []string) (fr []result.FileResults, err wg.Add(1) go func(path string) { defer wg.Done() - _ = p.processViolationInPath(path, done, rchan) + innerrchan := p.processViolationInPath(path, done) + for r := range innerrchan { + select { + case rchan <- r: + case <-done: + } + } }(paths[i]) } - wg.Wait() + go func() { + wg.Wait() + close(rchan) + }() for r := range rchan { fr = append(fr, *r) @@ -76,9 +85,10 @@ func (p *Parser) processViolations(paths []string) (fr []result.FileResults, err return } -func (p *Parser) processViolationInPath(path string, done <-chan struct{}, rchan chan *result.FileResults) error { +func (p *Parser) processViolationInPath(path string, done <-chan struct{}) chan *result.FileResults { // TODO: Handler errors files, _ := p.walkDir(path, done) + rchan := make(chan *result.FileResults) var wg sync.WaitGroup for f := range files { @@ -106,7 +116,7 @@ func (p *Parser) processViolationInPath(path string, done <-chan struct{}, rchan wg.Wait() close(rchan) }() - return nil + return rchan } func (p *Parser) walkDir(dirname string, done <-chan struct{}) (<-chan string, <-chan error) { diff --git a/pkg/parser/parser_test.go b/pkg/parser/parser_test.go index 7530b598..92182288 100644 --- a/pkg/parser/parser_test.go +++ b/pkg/parser/parser_test.go @@ -62,6 +62,12 @@ func TestParser_ParsePaths(t *testing.T) { assert.NoError(t, err) assert.Len(t, fr3, 0) + // Test with multiple paths supplied + // Disabled since this functionality is currently broken + frAll, err := p.ParsePaths(f1.Name(), f2.Name(), f3.Name()) + assert.NoError(t, err) + assert.Len(t, frAll, 1) + // Test ignored file f4, err := newFile("i have a whitelist violation, but am ignored\n") assert.NoError(t, err)