services/internal/pathperms: Fix synchronization.
Bug detected by:
go vet ./services/internal/pathperms
which reported errors like:
services/internal/pathperms/permsaccess.go:52: Get passes Lock by value:
pathperms.PathStore contains sync.Mutex
services/internal/pathperms/permsaccess.go:60: lockPath passes Lock by
value: pathperms.PathStore contains sync.Mutex
services/internal/pathperms/permsaccess.go:110: Set passes Lock by
value: pathperms.PathStore contains sync.Mutex
services/internal/pathperms/permsaccess.go:118: SetShareable passes Lock
by value: pathperms.PathStore contains sync.Mutex
services/internal/pathperms/permsaccess.go:190: PermsForPath passes Lock
by value: pathperms.PathStore contains sync.Mutex
Change-Id: I8dc76309ab19e265787d1af2c43817013c8fdb21
diff --git a/services/internal/pathperms/permsaccess.go b/services/internal/pathperms/permsaccess.go
index 6e463ac..81c6b76 100644
--- a/services/internal/pathperms/permsaccess.go
+++ b/services/internal/pathperms/permsaccess.go
@@ -49,7 +49,7 @@
}
// Get returns the Permissions from the data file in dir.
-func (store PathStore) Get(dir string) (access.Permissions, string, error) {
+func (store *PathStore) Get(dir string) (access.Permissions, string, error) {
permspath := filepath.Join(dir, permsName)
sigpath := filepath.Join(dir, sigName)
defer store.lockPath(dir)()
@@ -57,7 +57,7 @@
}
// TODO(rjkroege): Improve lock handling.
-func (store PathStore) lockPath(dir string) func() {
+func (store *PathStore) lockPath(dir string) func() {
store.lk.Lock()
lck, contains := store.pthlks[dir]
if !contains {
@@ -107,7 +107,7 @@
// Set writes the specified Permissions to the provided directory with
// enforcement of version synchronization mechanism and locking.
-func (store PathStore) Set(dir string, perms access.Permissions, version string) error {
+func (store *PathStore) Set(dir string, perms access.Permissions, version string) error {
return store.SetShareable(dir, perms, version, false)
}
@@ -115,7 +115,7 @@
// directory with enforcement of version synchronization mechanism and
// locking with file modes that will give the application read-only
// access to the permissions file.
-func (store PathStore) SetShareable(dir string, perms access.Permissions, version string, shareable bool) error {
+func (store *PathStore) SetShareable(dir string, perms access.Permissions, version string, shareable bool) error {
permspath := filepath.Join(dir, permsName)
sigpath := filepath.Join(dir, sigName)
defer store.lockPath(dir)()
@@ -187,7 +187,7 @@
return nil
}
-func (store PathStore) PermsForPath(path string) (access.Permissions, bool, error) {
+func (store *PathStore) PermsForPath(path string) (access.Permissions, bool, error) {
perms, _, err := store.Get(path)
if os.IsNotExist(err) {
return nil, true, nil