func (a *internalAPIServer) ListFile(ctx context.Context, request *pfs.ListFileRequest) (response *pfs.FileInfos, retErr error) { defer func(start time.Time) { a.Log(request, response, retErr, time.Since(start)) }(time.Now()) version, err := a.getVersion(ctx) if err != nil { return nil, err } shards, err := a.router.GetMasterShards(version) if err != nil { return nil, err } if request.Shard == nil { request.Shard = &pfs.Shard{Number: 0, Modulus: 1} } sharder := route.NewSharder(request.Shard.Modulus, 0) var wg sync.WaitGroup var lock sync.Mutex var fileInfos []*pfs.FileInfo var loopErr error for shard := range shards { shard := shard wg.Add(1) go func() { defer wg.Done() subFileInfos, err := a.driver.ListFile(request.File, shard) lock.Lock() defer lock.Unlock() if err != nil && err != pfs.ErrFileNotFound { if loopErr == nil { loopErr = err } return } for _, fileInfo := range subFileInfos { if sharder.GetShard(fileInfo.File) == request.Shard.Number || fileInfo.FileType == pfs.FileType_FILE_TYPE_DIR { fileInfos = append(fileInfos, fileInfo) } } }() } wg.Wait() if loopErr != nil { return nil, loopErr } return &pfs.FileInfos{ FileInfo: pfs.ReduceFileInfos(fileInfos), }, nil }
func (a *internalAPIServer) ListFile(ctx context.Context, request *pfs.ListFileRequest) (response *pfs.FileInfos, retErr error) { defer func(start time.Time) { a.Log(request, response, retErr, time.Since(start)) }(time.Now()) version, err := a.getVersion(ctx) if err != nil { return nil, err } shards, err := a.router.GetMasterShards(version) if err != nil { return nil, err } var wg sync.WaitGroup var lock sync.Mutex var fileInfos []*pfs.FileInfo var loopErr error for shard := range shards { shard := shard wg.Add(1) go func() { defer wg.Done() subFileInfos, err := a.driver.ListFile(request.File, request.Shard, shard) if err != nil && err != pfs.ErrFileNotFound { if loopErr == nil { loopErr = err } return } lock.Lock() defer lock.Unlock() fileInfos = append(fileInfos, subFileInfos...) }() } wg.Wait() if loopErr != nil { return nil, loopErr } return &pfs.FileInfos{ FileInfo: pfs.ReduceFileInfos(fileInfos), }, nil }