MCPcopy Create free account
hub / github.com/containerd/release-tool / parseModulesTxtDependencies

Function parseModulesTxtDependencies

util.go:85–123  ·  view source on GitHub ↗
(r io.Reader)

Source from the content-addressed store, hash-verified

83}
84
85func parseModulesTxtDependencies(r io.Reader) ([]dependency, error) {
86 var dependencies []dependency
87 s := bufio.NewScanner(r)
88 for s.Scan() {
89 ln := strings.TrimSpace(s.Text())
90 if ln == "" {
91 continue
92 }
93 parts := strings.Fields(ln)
94 if parts[0] != "#" {
95 continue
96 }
97
98 // See https://golang.org/ref/mod#go-mod-file-replace for
99 // syntax on replace directives
100 var commitOrVersionPart string
101 if len(parts) == 3 {
102 commitOrVersionPart = parts[2]
103 } else if len(parts) == 5 && parts[2] == "=>" {
104 // replace directive in go.mod without old version
105 // no need to care since it will has corresponding one with old version
106 continue
107 } else if len(parts) == 6 && parts[3] == "=>" {
108 commitOrVersionPart = parts[5]
109 } else if (len(parts) == 4 && parts[2] == "=>") || (len(parts) == 5 && parts[3] == "=>") {
110 // Ignore replace directive which uses filepath
111 continue
112 } else {
113 return nil, fmt.Errorf("%w: %s", errUnknownFormat, ln)
114 }
115 commitOrVersion, isSha := getCommitOrVersion(commitOrVersionPart)
116 if commitOrVersion == "" {
117 return nil, fmt.Errorf("%w: poorly formatted version in replace section %s", errUnknownFormat, parts[2])
118 }
119
120 dependencies = append(dependencies, formatDependency(parts[1], commitOrVersion, isSha))
121 }
122 return dependencies, nil
123}
124
125func parseGoModDependencies(r io.Reader) ([]dependency, error) {
126 var err error

Callers 1

parseDependenciesFunction · 0.85

Calls 2

getCommitOrVersionFunction · 0.85
formatDependencyFunction · 0.85

Tested by

no test coverage detected