From a295cd8007e270baf5eb97786ce7281360221037 Mon Sep 17 00:00:00 2001 From: George Tankersley Date: Fri, 17 Jun 2016 14:09:29 -0400 Subject: [PATCH] remove literal copy of sync.Mutex from memory store --- trustmanager/keyfilestore.go | 9 +++++---- trustmanager/memorystore.go | 21 ++++----------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/trustmanager/keyfilestore.go b/trustmanager/keyfilestore.go index e2f1d48a25..afec8b22f1 100644 --- a/trustmanager/keyfilestore.go +++ b/trustmanager/keyfilestore.go @@ -210,10 +210,11 @@ func NewKeyMemoryStore(passphraseRetriever notary.PassRetriever) *KeyMemoryStore keyInfoMap := make(keyInfoMap) - keyStore := &KeyMemoryStore{MemoryFileStore: *memStore, - PassRetriever: passphraseRetriever, - cachedKeys: cachedKeys, - keyInfoMap: keyInfoMap, + keyStore := &KeyMemoryStore{ + MemoryFileStore: *memStore, + PassRetriever: passphraseRetriever, + cachedKeys: cachedKeys, + keyInfoMap: keyInfoMap, } // Load this keystore's ID --> gun/role map diff --git a/trustmanager/memorystore.go b/trustmanager/memorystore.go index 9abf888ab9..d93e6c72c8 100644 --- a/trustmanager/memorystore.go +++ b/trustmanager/memorystore.go @@ -1,15 +1,11 @@ package trustmanager -import ( - "os" - "sync" -) +import "os" -// MemoryFileStore is an implementation of Storage that keeps -// the contents in memory. +// MemoryFileStore is an implementation of Storage that keeps the contents in +// memory. It is not thread-safe and should be used by a higher-level interface +// that provides locking. type MemoryFileStore struct { - sync.Mutex - files map[string][]byte } @@ -22,18 +18,12 @@ func NewMemoryFileStore() *MemoryFileStore { // Add writes data to a file with a given name func (f *MemoryFileStore) Add(name string, data []byte) error { - f.Lock() - defer f.Unlock() - f.files[name] = data return nil } // Remove removes a file identified by name func (f *MemoryFileStore) Remove(name string) error { - f.Lock() - defer f.Unlock() - if _, present := f.files[name]; !present { return os.ErrNotExist } @@ -44,9 +34,6 @@ func (f *MemoryFileStore) Remove(name string) error { // Get returns the data given a file name func (f *MemoryFileStore) Get(name string) ([]byte, error) { - f.Lock() - defer f.Unlock() - fileData, present := f.files[name] if !present { return nil, os.ErrNotExist