2024-11-27 21:40:06 -06:00
|
|
|
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
|
2024-12-13 00:19:33 -06:00
|
|
|
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")
|
|
|
|
}
|
2024-12-13 00:19:33 -06:00
|
|
|
// 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-11-27 21:40:06 -06:00
|
|
|
}
|
2024-12-15 12:14:48 -06:00
|
|
|
if !repo.Exists("go.sum") {
|
|
|
|
return errors.New("ValidGoSum() go.sum is missing")
|
2024-11-27 21:40:06 -06:00
|
|
|
}
|
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")
|
|
|
|
}
|
|
|
|
*/
|
2024-12-13 00:19:33 -06:00
|
|
|
return nil
|
2024-11-27 21:40:06 -06:00
|
|
|
}
|
|
|
|
|
2024-12-01 15:10:55 -06:00
|
|
|
func (repo *Repo) GoDepsLen() int {
|
|
|
|
if repo.GoDeps == nil {
|
|
|
|
return 0
|
|
|
|
}
|
2024-12-13 00:19:33 -06:00
|
|
|
return len(repo.GoDeps.GoDeps)
|
2024-12-01 15:10:55 -06:00
|
|
|
}
|