2016-02-13 01:18:06 -08:00
|
|
|
package vain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2016-02-13 10:44:41 -08:00
|
|
|
"strings"
|
2016-02-13 01:18:06 -08:00
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
2016-02-13 10:44:41 -08:00
|
|
|
func Valid(p string, packages []Package) bool {
|
|
|
|
for _, pkg := range packages {
|
|
|
|
if strings.HasPrefix(pkg.Path, p) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2016-02-13 01:18:06 -08:00
|
|
|
type MemStore struct {
|
|
|
|
l sync.RWMutex
|
|
|
|
p map[string]Package
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMemStore() *MemStore {
|
|
|
|
return &MemStore{
|
|
|
|
p: make(map[string]Package),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms MemStore) Add(p Package) error {
|
|
|
|
ms.l.Lock()
|
|
|
|
ms.p[p.Path] = p
|
|
|
|
ms.l.Unlock()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms MemStore) Remove(path string) error {
|
|
|
|
ms.l.Lock()
|
|
|
|
delete(ms.p, path)
|
|
|
|
ms.l.Unlock()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms MemStore) Save() error {
|
|
|
|
return errors.New("save is not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms MemStore) All() []Package {
|
|
|
|
r := []Package{}
|
|
|
|
ms.l.RLock()
|
|
|
|
for _, p := range ms.p {
|
|
|
|
r = append(r, p)
|
|
|
|
}
|
|
|
|
ms.l.RUnlock()
|
|
|
|
return r
|
|
|
|
}
|