vain/storage.go
stephen mcquay 557717c138 Prevent addition of duplicate path prefixes.
I think I understand this now; the failure comes from here:

https://golang.org/src/cmd/go/vcs.go#L818

and makes it so one can't both host:
- github.com/foo
- github.com/foo/bar

which would have to clone the latter inside of the former.

Fixes #1.
2016-02-13 10:46:09 -08:00

56 lines
804 B
Go

package vain
import (
"errors"
"strings"
"sync"
)
func Valid(p string, packages []Package) bool {
for _, pkg := range packages {
if strings.HasPrefix(pkg.Path, p) {
return false
}
}
return true
}
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
}