Merge pull request #1663 from dmcgowan/content-local-labels

content: add support for label storage in local content store
This commit is contained in:
Stephen Day
2017-11-01 11:24:15 -07:00
committed by GitHub
8 changed files with 178 additions and 16 deletions

View File

@@ -14,6 +14,7 @@ import (
"path/filepath"
"reflect"
"runtime"
"sync"
"testing"
"time"
@@ -23,9 +24,55 @@ import (
"github.com/opencontainers/go-digest"
)
type memoryLabelStore struct {
l sync.Mutex
labels map[digest.Digest]map[string]string
}
func newMemoryLabelStore() LabelStore {
return &memoryLabelStore{
labels: map[digest.Digest]map[string]string{},
}
}
func (mls *memoryLabelStore) Get(d digest.Digest) (map[string]string, error) {
mls.l.Lock()
labels := mls.labels[d]
mls.l.Unlock()
return labels, nil
}
func (mls *memoryLabelStore) Set(d digest.Digest, labels map[string]string) error {
mls.l.Lock()
mls.labels[d] = labels
mls.l.Unlock()
return nil
}
func (mls *memoryLabelStore) Update(d digest.Digest, update map[string]string) (map[string]string, error) {
mls.l.Lock()
labels, ok := mls.labels[d]
if !ok {
labels = map[string]string{}
}
for k, v := range update {
if v == "" {
delete(labels, k)
} else {
labels[k] = v
}
}
mls.labels[d] = labels
mls.l.Unlock()
return labels, nil
}
func TestContent(t *testing.T) {
testsuite.ContentSuite(t, "fs", func(ctx context.Context, root string) (content.Store, func() error, error) {
cs, err := NewStore(root)
cs, err := NewLabeledStore(root, newMemoryLabelStore())
if err != nil {
return nil, nil, err
}