Skip to content

Commit

Permalink
fix: list projects with thread safe
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoh86 committed Dec 18, 2024
1 parent 7f77e9c commit 29e749b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/gogh/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
if err != nil {
return err
}
log.FromContext(ctx).Debugf("found %d projects in %q", len(projects), root)
for _, project := range projects {
str, err := f.Format(project)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions local.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"strings"
"sync"

"github.com/apex/log"
git "github.com/go-git/go-git/v5"
Expand Down Expand Up @@ -208,6 +209,8 @@ type LocalWalkOption struct {
Query string
}

var mu sync.Mutex

func (l *LocalController) Walk(
ctx context.Context,
opt *LocalWalkOption,
Expand Down Expand Up @@ -251,6 +254,8 @@ func (l *LocalController) Walk(
if opt != nil && !strings.Contains(p.RelPath(), opt.Query) {
return nil
}
mu.Lock()
defer mu.Unlock()
return walkFn(p)
})
}
Expand Down

0 comments on commit 29e749b

Please sign in to comment.