Skip to content

Commit

Permalink
fix reace condition; add waitgroups
Browse files Browse the repository at this point in the history
Signed-off-by: MUzairS15 <muzair.shaikh810@gmail.com>
  • Loading branch information
MUzairS15 committed Jun 15, 2024
1 parent 202100b commit 1252afb
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 1252afb

Please sign in to comment.