Skip to content

Commit

Permalink
Fix panic when multiple paths are supplied
Browse files Browse the repository at this point in the history
  • Loading branch information
caitlinelfring committed Sep 2, 2020
1 parent 59b924c commit 4637d46
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,31 @@ 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)
}
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 {
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions pkg/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4637d46

Please sign in to comment.