forked from Masterminds/glide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracker.go
42 lines (35 loc) · 876 Bytes
/
tracker.go
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
package repo
import (
"sync"
)
// UpdateTracker holds a list of all the packages that have been updated from
// an external source. This is a concurrency safe implementation.
type UpdateTracker struct {
sync.RWMutex
updated map[string]bool
}
// NewUpdateTracker creates a new instance of UpdateTracker ready for use.
func NewUpdateTracker() *UpdateTracker {
u := &UpdateTracker{}
u.updated = map[string]bool{}
return u
}
// Add adds a name to the list of items being tracked.
func (u *UpdateTracker) Add(name string) {
u.Lock()
u.updated[name] = true
u.Unlock()
}
// Check returns if an item is on the list or not.
func (u *UpdateTracker) Check(name string) bool {
u.RLock()
_, f := u.updated[name]
u.RUnlock()
return f
}
// Remove takes a package off the list
func (u *UpdateTracker) Remove(name string) {
u.Lock()
delete(u.updated, name)
u.Unlock()
}