2024-01-29 09:31:22 -06:00
|
|
|
package repostatus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (rs *RepoStatus) GetGoDeps() GoConfig {
|
|
|
|
tmp := filepath.Join(rs.realPath.String(), "go.sum")
|
|
|
|
gosum, err := os.Open(tmp)
|
|
|
|
if err != nil {
|
2024-03-09 16:50:18 -06:00
|
|
|
log.Log(REPO, "\tmissing go.sum", rs.realPath.String())
|
2024-01-29 09:31:22 -06:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
defer gosum.Close()
|
|
|
|
|
|
|
|
var deps GoConfig
|
|
|
|
deps = make(GoConfig)
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(gosum)
|
2024-03-09 16:50:18 -06:00
|
|
|
log.Log(REPO, "\tgosum:", tmp)
|
2024-01-29 09:31:22 -06:00
|
|
|
for scanner.Scan() {
|
|
|
|
line := strings.TrimSpace(scanner.Text())
|
|
|
|
|
|
|
|
parts := strings.Split(line, " ")
|
|
|
|
if len(parts) == 3 {
|
|
|
|
godep := strings.TrimSpace(parts[0])
|
|
|
|
version := strings.TrimSpace(parts[1])
|
|
|
|
if strings.HasSuffix(version, "/go.mod") {
|
|
|
|
version = strings.TrimSuffix(version, "/go.mod")
|
|
|
|
}
|
|
|
|
currentversion, ok := deps[godep]
|
|
|
|
if ok {
|
|
|
|
if currentversion != version {
|
2024-03-09 16:50:18 -06:00
|
|
|
log.Log(REPO, "\tREPO:", rs.String(), rs.realPath.String())
|
|
|
|
log.Log(REPO, "\t version mismatch:", godep, version, currentversion)
|
2024-01-29 09:31:22 -06:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
deps[godep] = version
|
2024-03-09 16:50:18 -06:00
|
|
|
log.Log(REPO, "\t", godep, "=", version)
|
2024-01-29 09:31:22 -06:00
|
|
|
}
|
|
|
|
} else {
|
2024-03-09 16:50:18 -06:00
|
|
|
log.Log(REPO, "\t INVALID:", parts)
|
2024-01-29 09:31:22 -06:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return deps
|
|
|
|
}
|