gitpb/goDep.redoGoMod.go

58 lines
1.2 KiB
Go
Raw Normal View History

package gitpb
// does processing on the go.mod and go.sum files
import (
"errors"
)
2024-12-15 12:14:48 -06:00
// checks to see if the go.sum and go.mod files exist
// also check for a match with the repo.pb GoPrimitive bool
// todo: check mtime
func (repo *Repo) ValidGoSum() error {
2024-12-15 12:14:48 -06:00
if !repo.Exists("go.mod") {
return errors.New("ValidGoSum() go.mod is missing")
}
2024-12-17 06:37:14 -06:00
if repo.GoInfo.GoPrimitive {
2024-12-15 12:14:48 -06:00
if !repo.Exists("go.mod") {
return errors.New("GoPrimitive == true, but go.mod is missing")
}
// repo thinks it is primitive but has a go.sum file
if repo.Exists("go.sum") {
return errors.New("GoPrimitive == true, but go.sum exists")
}
2024-12-15 12:14:48 -06:00
/*
// todo: fix this
2024-12-17 00:00:49 -06:00
mtime, err := repo.Mtime("go.mod")
2024-12-15 12:14:48 -06:00
if err == nil {
return err
}
if mtime != repo.LastGoDep.AsTime() {
return errors.New("go.mod mtime mis-match")
}
*/
return nil
}
2024-12-15 12:14:48 -06:00
if !repo.Exists("go.sum") {
return errors.New("ValidGoSum() go.sum is missing")
}
2024-12-15 12:14:48 -06:00
/*
2024-12-17 00:00:49 -06:00
mtime, err := repo.Mtime("go.sum")
2024-12-15 12:14:48 -06:00
// todo: fix this
if err == nil {
return err
}
if mtime != repo.LastGoDep.AsTime() {
return errors.New("go.sum mtime mis-match")
}
*/
return nil
}
func (repo *Repo) GoDepsLen() int {
if repo.GoDeps == nil {
return 0
}
return len(repo.GoDeps.GoDeps)
}