2024-11-27 21:40:06 -06:00
|
|
|
package gitpb
|
|
|
|
|
|
|
|
// does processing on the go.mod and go.sum files
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2024-12-13 00:19:33 -06:00
|
|
|
"time"
|
2024-11-27 21:40:06 -06:00
|
|
|
)
|
|
|
|
|
2024-12-13 00:19:33 -06:00
|
|
|
// checks to see if the go.sum and go.mod files
|
|
|
|
// match the repo.pb information
|
|
|
|
func (repo *Repo) ValidGoSum() error {
|
|
|
|
if repo.GoPrimitive {
|
|
|
|
// 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")
|
|
|
|
}
|
|
|
|
mtime, err := repo.mtime("go.mod")
|
|
|
|
if err == nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if mtime != repo.LastGoDep.AsTime() {
|
|
|
|
return errors.New("go.mod mtime mis-match")
|
|
|
|
}
|
2024-11-27 21:40:06 -06:00
|
|
|
}
|
2024-12-13 00:19:33 -06:00
|
|
|
mtime, err := repo.mtime("go.sum")
|
|
|
|
if err == nil {
|
|
|
|
return err
|
2024-11-27 21:40:06 -06:00
|
|
|
}
|
2024-12-13 00:19:33 -06:00
|
|
|
if mtime != repo.LastGoDep.AsTime() {
|
|
|
|
return errors.New("go.sum mtime mis-match")
|
2024-11-27 21:40:06 -06:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2024-12-13 00:19:33 -06:00
|
|
|
func (repo *Repo) LastGitPull() (time.Time, error) {
|
|
|
|
return repo.mtime(".git/FETCH_HEAD")
|
2024-12-01 15:10:55 -06:00
|
|
|
}
|
|
|
|
|
2024-12-13 00:19:33 -06:00
|
|
|
func (repo *Repo) GoSumAge() (time.Duration, error) {
|
|
|
|
var mtime time.Time
|
|
|
|
var err error
|
|
|
|
mtime, err = repo.mtime("go.sum")
|
|
|
|
if err == nil {
|
|
|
|
return time.Since(mtime), nil
|
2024-12-01 15:10:55 -06:00
|
|
|
}
|
2024-12-13 00:19:33 -06:00
|
|
|
mtime, err = repo.mtime("go.mod")
|
|
|
|
if err == nil {
|
|
|
|
return time.Since(mtime), nil
|
2024-12-01 15:10:55 -06:00
|
|
|
}
|
2024-12-13 00:19:33 -06:00
|
|
|
now := time.Now()
|
|
|
|
return time.Since(now), errors.New(repo.GoPath + " go.mod missing")
|
2024-12-01 15:10:55 -06:00
|
|
|
}
|