mirror of
https://github.com/ossf/scorecard.git
synced 2024-11-04 03:52:31 +03:00
🐛 Fix ListFiles caching in localrepo client (#1190)
* fix * remove debug
This commit is contained in:
parent
87359619c7
commit
608866949b
@ -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) {
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user