Skip to content

Commit

Permalink
fix(fs Profile Store): fix lock pass-by-value error
Browse files Browse the repository at this point in the history
and other things caught by go vet
  • Loading branch information
b5 committed Nov 2, 2018
1 parent 8581a25 commit a22515a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
1 change: 0 additions & 1 deletion cmd/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func EnvPathFactory() (string, string) {
home, err := homedir.Dir()
if err != nil {
panic(err)
return "", ""
}

qriRepoPath := os.Getenv("QRI_PATH")
Expand Down
6 changes: 5 additions & 1 deletion lib/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ func (sr *SearchRequests) Search(p *SearchParams, results *[]SearchResult) error
if reg == nil {
return repo.ErrNoRegistry
}
params := &regclient.SearchParams{p.QueryString, nil, p.Limit, p.Offset}
params := &regclient.SearchParams{
QueryString: p.QueryString,
Limit: p.Limit,
Offset: p.Offset,
}

regResults, err := reg.Search(params)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion repo/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Repo struct {
selectedRefs []repo.DatasetRef
graph map[string]*dsgraph.Node

profiles ProfileStore
profiles *ProfileStore
index search.Index

registry *regclient.Client
Expand Down
20 changes: 10 additions & 10 deletions repo/fs/profile_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ type ProfileStore struct {
}

// NewProfileStore allocates a ProfileStore
func NewProfileStore(bp basepath) ProfileStore {
return ProfileStore{
func NewProfileStore(bp basepath) *ProfileStore {
return &ProfileStore{
basepath: bp,
flock: flock.NewFlock(bp.filepath(FilePeers) + ".lock"),
}
}

// PutProfile adds a peer to the store
func (r ProfileStore) PutProfile(p *profile.Profile) error {
func (r *ProfileStore) PutProfile(p *profile.Profile) error {
log.Debugf("put profile: %s", p.ID.String())
if p.ID.String() == "" {
return fmt.Errorf("profile ID is required")
Expand All @@ -61,7 +61,7 @@ func (r ProfileStore) PutProfile(p *profile.Profile) error {
}

// PeerIDs gives the peer.IDs list for a given peername
func (r ProfileStore) PeerIDs(id profile.ID) ([]peer.ID, error) {
func (r *ProfileStore) PeerIDs(id profile.ID) ([]peer.ID, error) {
r.Lock()
defer r.Unlock()

Expand All @@ -86,7 +86,7 @@ func (r ProfileStore) PeerIDs(id profile.ID) ([]peer.ID, error) {
}

// List hands back the list of peers
func (r ProfileStore) List() (map[profile.ID]*profile.Profile, error) {
func (r *ProfileStore) List() (map[profile.ID]*profile.Profile, error) {
r.Lock()
defer r.Unlock()

Expand All @@ -110,7 +110,7 @@ func (r ProfileStore) List() (map[profile.ID]*profile.Profile, error) {
}

// PeernameID gives the profile.ID for a given peername
func (r ProfileStore) PeernameID(peername string) (profile.ID, error) {
func (r *ProfileStore) PeernameID(peername string) (profile.ID, error) {
r.Lock()
defer r.Unlock()

Expand All @@ -128,7 +128,7 @@ func (r ProfileStore) PeernameID(peername string) (profile.ID, error) {
}

// GetProfile fetches a profile from the store
func (r ProfileStore) GetProfile(id profile.ID) (*profile.Profile, error) {
func (r *ProfileStore) GetProfile(id profile.ID) (*profile.Profile, error) {
log.Debugf("get profile: %s", id.String())

r.Lock()
Expand All @@ -153,7 +153,7 @@ func (r ProfileStore) GetProfile(id profile.ID) (*profile.Profile, error) {
}

// PeerProfile gives the profile that corresponds with a given peer.ID
func (r ProfileStore) PeerProfile(id peer.ID) (*profile.Profile, error) {
func (r *ProfileStore) PeerProfile(id peer.ID) (*profile.Profile, error) {
log.Debugf("peerProfile: %s", id.Pretty())

r.Lock()
Expand All @@ -179,7 +179,7 @@ func (r ProfileStore) PeerProfile(id peer.ID) (*profile.Profile, error) {
}

// DeleteProfile removes a profile from the store
func (r ProfileStore) DeleteProfile(id profile.ID) error {
func (r *ProfileStore) DeleteProfile(id profile.ID) error {
r.Lock()
defer r.Unlock()

Expand All @@ -191,7 +191,7 @@ func (r ProfileStore) DeleteProfile(id profile.ID) error {
return r.saveFile(ps, FilePeers)
}

func (r ProfileStore) saveFile(ps map[string]*config.ProfilePod, f File) error {
func (r *ProfileStore) saveFile(ps map[string]*config.ProfilePod, f File) error {

data, err := json.Marshal(ps)
if err != nil {
Expand Down

0 comments on commit a22515a

Please sign in to comment.