summaryrefslogtreecommitdiff
path: root/godep.helpers.go
blob: 007cc61a72327a71cd17ec63e7dd331a7110e296 (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
package gitpb

// this is becoming a standard format
// todo: autogenerate this from the .proto file?

import (
	"time"
)

func (repo *Repo) DeleteGoDepByHash(hash string) *GoDep {
	refslock.Lock()
	defer refslock.Unlock()

	for i, _ := range repo.GoDeps {
		if repo.GoDeps[i].Hash == hash {
			repo.GoDeps[i] = repo.GoDeps[len(repo.GoDeps)-1]
			repo.GoDeps = repo.GoDeps[:len(repo.GoDeps)-1]
			return nil
		}
	}
	return nil
}

// enforces no duplicate package names
func (repo *Repo) AppendGoDep(newP *GoDep) bool {
	refslock.Lock()
	defer refslock.Unlock()

	for _, p := range repo.GoDeps {
		if p.GoPath == newP.GoPath {
			return false
		}
	}

	repo.GoDeps = append(repo.GoDeps, newP)
	return true
}

// returns time.Duration since last scan of go.sum & go.mod
func (repo *Repo) AgeGoDep() time.Duration {
	t := time.Since(repo.LastGoDep.AsTime())
	return t
}

// find a dependancy by the go path
func (repo *Repo) FindGoDepByPath(gopath string) *GoDep {
	refslock.RLock()
	defer refslock.RUnlock()

	for _, p := range repo.GoDeps {
		if p.GoPath == gopath {
			return p
		}
	}

	return nil
}