github.com/kngu9/glide@v0.0.0-20160505135211-e73500c73591/repo/tracker.go (about)

     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  }