summaryrefslogtreecommitdiff
path: root/goDep.redoGoMod.go
blob: 59845afd1e7e91a80a12c89f0afff5af4e69d7ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package gitpb

// does processing on the go.mod and go.sum files

import (
	"errors"
	"time"
)

// 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 {
	if !repo.Exists("go.mod") {
		return errors.New("ValidGoSum() go.mod is missing")
	}
	if repo.GoPrimitive {
		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")
		}
		/*
			// todo: fix this
				mtime, err := repo.mtime("go.mod")
				if err == nil {
					return err
				}
				if mtime != repo.LastGoDep.AsTime() {
					return errors.New("go.mod mtime mis-match")
				}
		*/
		return nil
	}
	if !repo.Exists("go.sum") {
		return errors.New("ValidGoSum() go.sum is missing")
	}
	/*
		mtime, err := repo.mtime("go.sum")
			// 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)
}

func (repo *Repo) LastGitPull() (time.Time, error) {
	return repo.mtime(".git/FETCH_HEAD")
}

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
	}
	mtime, err = repo.mtime("go.mod")
	if err == nil {
		return time.Since(mtime), nil
	}
	now := time.Now()
	return time.Since(now), errors.New(repo.GoPath + " go.mod missing")
}