Skip to content

Commit

Permalink
Merge pull request #918 from rsteube/storage-mutex-defer
Browse files Browse the repository at this point in the history
storage: use defer
  • Loading branch information
rsteube authored Sep 16, 2023
2 parents f3f8d72 + fbb1cac commit 0e0f241
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,16 @@ func (s _storage) getPositional(cmd *cobra.Command, index int) Action {
func (s _storage) check() []string {
errors := make([]string, 0)
for cmd, entry := range s {
entry.flagMutex.RLock()
for name := range entry.flag {
if flag := cmd.LocalFlags().Lookup(name); flag == nil {
errors = append(errors, fmt.Sprintf("unknown flag for %s: %s\n", uid.Command(cmd), name))
func() {
entry.flagMutex.RLock()
defer entry.flagMutex.RUnlock()

for name := range entry.flag {
if flag := cmd.LocalFlags().Lookup(name); flag == nil {
errors = append(errors, fmt.Sprintf("unknown flag for %s: %s\n", uid.Command(cmd), name))
}
}
}
entry.flagMutex.RUnlock()
}()
}
return errors
}
Expand Down

0 comments on commit 0e0f241

Please sign in to comment.