2024-12-03 00:35:50 -06:00
|
|
|
package gitpb
|
|
|
|
|
|
|
|
// does processing on the go.mod and go.sum files
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
// reads and parses the go.sum file
|
|
|
|
// does not change anything
|
|
|
|
func (repo *Repo) ParseGoSum() (bool, error) {
|
|
|
|
// empty out what was there before
|
|
|
|
repo.GoDeps = nil
|
2024-12-03 22:36:06 -06:00
|
|
|
|
|
|
|
// check of the repo is a primative
|
|
|
|
// that means, there is not a go.sum file
|
|
|
|
// because the package is completely self contained!
|
2024-12-15 15:53:08 -06:00
|
|
|
if err := repo.SetPrimitive(); err == nil {
|
2024-12-03 22:36:06 -06:00
|
|
|
log.Info("This repo is primative!")
|
|
|
|
return true, nil
|
|
|
|
}
|
2024-12-03 00:35:50 -06:00
|
|
|
tmp := filepath.Join(repo.FullPath, "go.sum")
|
|
|
|
gosum, err := os.Open(tmp)
|
2024-12-03 22:36:06 -06:00
|
|
|
defer gosum.Close()
|
2024-12-03 00:35:50 -06:00
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(gosum)
|
|
|
|
log.Info("gosum:", tmp)
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
new1 := GoDep{
|
|
|
|
GoPath: godep,
|
|
|
|
Version: version,
|
|
|
|
}
|
|
|
|
if repo.GoDeps == nil {
|
|
|
|
repo.GoDeps = new(GoDeps)
|
|
|
|
}
|
|
|
|
repo.GoDeps.AppendUniqueGoPath(&new1)
|
|
|
|
} else {
|
|
|
|
return false, errors.New("go.sum parse error invalid: " + line)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
|
|
repo.GoDeps = nil
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
2024-12-17 06:37:14 -06:00
|
|
|
/*
|
2024-12-03 00:35:50 -06:00
|
|
|
// reads and parses the go.sum file
|
|
|
|
// is identical to the one above, change that
|
|
|
|
func (repo *Repo) UpdatePublished() (bool, error) {
|
|
|
|
// empty out what was there before
|
|
|
|
repo.Published = nil
|
|
|
|
tmp := filepath.Join(repo.FullPath, "go.sum")
|
|
|
|
gosum, err := os.Open(tmp)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("missing go.sum", repo.FullPath)
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
defer gosum.Close()
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(gosum)
|
|
|
|
log.Info("gosum:", tmp)
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
new1 := GoDep{
|
|
|
|
GoPath: godep,
|
|
|
|
Version: version,
|
|
|
|
}
|
|
|
|
if repo.Published == nil {
|
|
|
|
repo.Published = new(GoDeps)
|
|
|
|
}
|
|
|
|
repo.Published.AppendUniqueGoPath(&new1)
|
|
|
|
} else {
|
|
|
|
return false, errors.New("go.sum parse error invalid: " + line)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
|
|
repo.Published = nil
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}
|
2024-12-17 06:37:14 -06:00
|
|
|
*/
|