func (a *internalAPIServer) ListFile(ctx context.Context, request *pfs.ListFileRequest) (response *pfs.FileInfos, err error) { defer func(start time.Time) { a.Log(request, response, err, 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 seenDirectories := make(map[string]bool) var loopErr error for shard := range shards { wg.Add(1) go func(shard uint64) { defer wg.Done() subFileInfos, err := a.driver.ListFile(request.File, shard) lock.Lock() defer lock.Unlock() if err != nil { if loopErr == nil { loopErr = err } return } for _, fileInfo := range subFileInfos { if fileInfo.FileType == pfs.FileType_FILE_TYPE_DIR { if seenDirectories[fileInfo.File.Path] { continue } seenDirectories[fileInfo.File.Path] = true } if sharder.GetShard(fileInfo.File) == request.Shard.Number { fileInfos = append(fileInfos, fileInfo) } } }(shard) } wg.Wait() if loopErr != nil { return nil, loopErr } return &pfs.FileInfos{ FileInfo: 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 } 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 }