Skip to content

Commit

Permalink
🐛 Fix ListFiles caching in localrepo client (#1190)
Browse files Browse the repository at this point in the history
* fix

* remove debug
  • Loading branch information
laurentsimon authored Oct 29, 2021
1 parent 8735961 commit 6088669
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
21 changes: 10 additions & 11 deletions clients/localdir/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ var (
errInputRepoType = errors.New("input repo should be of type repoLocal")
)

var once sync.Once

//nolint:govet
type localDirClient struct {
logger *zap.Logger
ctx context.Context
path string
logger *zap.Logger
ctx context.Context
path string
once sync.Once
errFiles error
files []string
}

// InitRepo sets up the local repo.
Expand Down Expand Up @@ -116,14 +118,11 @@ func listFiles(clientPath string, predicate func(string) (bool, error)) ([]strin

// ListFiles implements RepoClient.ListFiles.
func (client *localDirClient) ListFiles(predicate func(string) (bool, error)) ([]string, error) {
files := []string{}
var err error

once.Do(func() {
files, err = listFiles(client.path, predicate)
client.once.Do(func() {
client.files, client.errFiles = listFiles(client.path, predicate)
})

return files, err
return client.files, client.errFiles
}

func getFileContent(clientpath, filename string) ([]byte, error) {
Expand Down
4 changes: 2 additions & 2 deletions clients/localdir/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestClient_CreationAndCaching(t *testing.T) {
ctx := context.Background()
logger, err := githubrepo.NewLogger(zapcore.DebugLevel)
if err != nil {
t.Errorf("githubrepo.NewLogger: %w", err)
t.Errorf("githubrepo.NewLogger: %v", err)
}
// nolint
defer logger.Sync() // Flushes buffer, if any.
Expand All @@ -82,7 +82,7 @@ func TestClient_CreationAndCaching(t *testing.T) {

client := CreateLocalDirClient(ctx, logger)
if err := client.InitRepo(repo); err != nil {
t.Errorf("InitRepo: %w", err)
t.Errorf("InitRepo: %v", err)
}

// List files.
Expand Down

0 comments on commit 6088669

Please sign in to comment.