(ctx context.Context, parent *model.File, files []*model.File, call model.ResCallback)
| 23 | } |
| 24 | |
| 25 | func (sca Sca) Sca(ctx context.Context, parent *model.File, files []*model.File, call model.ResCallback) { |
| 26 | |
| 27 | jsonMap := map[string]*ComposerJson{} |
| 28 | lockMap := map[string]*ComposerLock{} |
| 29 | |
| 30 | path2dir := func(relpath string) string { return path.Dir(strings.ReplaceAll(relpath, `\`, `/`)) } |
| 31 | |
| 32 | for _, f := range files { |
| 33 | if filter.PhpComposer(f.Relpath()) { |
| 34 | f.OpenReader(func(reader io.Reader) { |
| 35 | var js ComposerJson |
| 36 | json.NewDecoder(reader).Decode(&js) |
| 37 | js.File = f |
| 38 | jsonMap[path2dir(f.Relpath())] = &js |
| 39 | }) |
| 40 | } else if filter.PhpComposerLock(f.Relpath()) { |
| 41 | f.OpenReader(func(reader io.Reader) { |
| 42 | var lock ComposerLock |
| 43 | json.NewDecoder(reader).Decode(&lock) |
| 44 | lockMap[path2dir(f.Relpath())] = &lock |
| 45 | }) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | loop: |
| 50 | for dir, json := range jsonMap { |
| 51 | |
| 52 | // 通过lock文件补全 |
| 53 | if lock, ok := lockMap[dir]; ok { |
| 54 | call(json.File, ParseComposerJsonWithLock(json, lock)) |
| 55 | continue |
| 56 | } |
| 57 | |
| 58 | // vendor中的composer.json没有对应lock则不做处理 |
| 59 | for dir := range strings.SplitSeq(dir, "/") { |
| 60 | if strings.EqualFold(dir, "vendor") { |
| 61 | continue loop |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | select { |
| 66 | case <-ctx.Done(): |
| 67 | return |
| 68 | default: |
| 69 | } |
| 70 | |
| 71 | // 从数据源下载 |
| 72 | call(json.File, ParseComposerJsonWithOrigin(json)) |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | var defaultComposerRepo = []common.RepoConfig{ |
| 77 | {Url: "http://repo.packagist.org/p2"}, |
nothing calls this directly
no test coverage detected