repo/tracker.go   A
last analyzed

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 23
dl 0
loc 41
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A repo.*UpdateTracker.Remove 0 4 1
A repo.NewUpdateTracker 0 4 1
A repo.*UpdateTracker.Check 0 5 1
A repo.*UpdateTracker.Add 0 4 1
1
package repo
2
3
import (
4
	"sync"
5
)
6
7
// UpdateTracker holds a list of all the packages that have been updated from
8
// an external source. This is a concurrency safe implementation.
9
type UpdateTracker struct {
10
	sync.RWMutex
11
12
	updated map[string]bool
13
}
14
15
// NewUpdateTracker creates a new instance of UpdateTracker ready for use.
16
func NewUpdateTracker() *UpdateTracker {
17
	u := &UpdateTracker{}
18
	u.updated = map[string]bool{}
19
	return u
20
}
21
22
// Add adds a name to the list of items being tracked.
23
func (u *UpdateTracker) Add(name string) {
24
	u.Lock()
25
	u.updated[name] = true
26
	u.Unlock()
27
}
28
29
// Check returns if an item is on the list or not.
30
func (u *UpdateTracker) Check(name string) bool {
31
	u.RLock()
32
	_, f := u.updated[name]
33
	u.RUnlock()
34
	return f
35
}
36
37
// Remove takes a package off the list
38
func (u *UpdateTracker) Remove(name string) {
39
	u.Lock()
40
	delete(u.updated, name)
41
	u.Unlock()
42
}
43