Skip to content

Commit

Permalink
Merge pull request #510 from MUzairS15/git/walker
Browse files Browse the repository at this point in the history
fix race condition; add waitgroups
  • Loading branch information
Mohd Uzair authored Jun 15, 2024
2 parents 202100b + 1252afb commit ceae4d8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion utils/walker/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"
"strconv"
"strings"
"sync"
"time"

"github.com/go-git/go-git/v5"
Expand Down Expand Up @@ -136,7 +137,7 @@ func (g *Git) RegisterDirInterceptor(i DirInterceptor) *Git {
}
func clonewalk(g *Git) error {
if g.maxFileSizeInBytes == 0 {
return ErrInvalidSizeFile(errors.New("Max file size passed as 0. Will not read any file"))
return ErrInvalidSizeFile(errors.New("max file size passed as 0. Will not read any file"))
}

path := filepath.Join(os.TempDir(), g.repo, strconv.FormatInt(time.Now().UTC().UnixNano(), 10))
Expand Down Expand Up @@ -214,11 +215,14 @@ func clonewalk(g *Git) error {
files = append(files, file)
}

var wg sync.WaitGroup
for _, f := range files {
fPath := filepath.Join(path, g.root, f.Name())
if f.IsDir() && g.dirInterceptor != nil {
name := f.Name()
wg.Add(1)
go func(name string, path string, filename string) {
defer wg.Done()
err := g.dirInterceptor(Directory{
Name: filename,
Path: fPath,
Expand All @@ -237,6 +241,7 @@ func clonewalk(g *Git) error {
fmt.Println(err.Error())
}
}
wg.Wait()

return nil
}
Expand Down

0 comments on commit ceae4d8

Please sign in to comment.