🐛 Fix ListFiles caching in localrepo client (#1190)

* fix

* remove debug
This commit is contained in:
laurentsimon 2021-10-28 20:12:44 -07:00 committed by GitHub
parent 87359619c7
commit 608866949b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 13 deletions

View File

@ -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.
@ -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) {

View File

@ -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.
@ -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.