Skip to content

Commit

Permalink
remove literal copy of sync.Mutex from memory store
Browse files Browse the repository at this point in the history
Signed-off-by: George Tankersley <george.tankersley@gmail.com>
  • Loading branch information
gtank committed Jun 17, 2016
1 parent d1e910b commit 0d69ee3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
9 changes: 5 additions & 4 deletions trustmanager/keyfilestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 4 additions & 17 deletions trustmanager/memorystore.go
Original file line number Diff line number Diff line change
@@ -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
}

Expand All @@ -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
}
Expand All @@ -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
Expand Down

0 comments on commit 0d69ee3

Please sign in to comment.