From 6dba9636086d7b791d366ebe5c9f98f9148342b7 Mon Sep 17 00:00:00 2001 From: brent s Date: Mon, 13 Dec 2021 04:33:43 -0500 Subject: [PATCH] fixing some race conditions --- collection_funcs.go | 18 +++++++++++++----- item_funcs.go | 30 ++++++++++++++++++++++-------- service_funcs.go | 10 ++++++++-- 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/collection_funcs.go b/collection_funcs.go index 5b24169..2444745 100644 --- a/collection_funcs.go +++ b/collection_funcs.go @@ -30,11 +30,19 @@ func NewCollection(service *Service, path dbus.ObjectPath) (coll *Collection, er } // Populate the struct fields... - // TODO: use channel for errors; condense into a MultiError. - go coll.Locked() - go coll.Label() - go coll.Created() - go coll.Modified() + // TODO: use channel for errors; condense into a MultiError and switch to goroutines. + if _, err = coll.Locked(); err != nil { + return + } + if _, err = coll.Label(); err != nil { + return + } + if _, err = coll.Created(); err != nil { + return + } + if _, _, err = coll.Modified(); err != nil { + return + } return } diff --git a/item_funcs.go b/item_funcs.go index 5859a2c..0532618 100644 --- a/item_funcs.go +++ b/item_funcs.go @@ -34,14 +34,28 @@ func NewItem(collection *Collection, path dbus.ObjectPath) (item *Item, err erro item.collection = collection // Populate the struct fields... - // TODO: use channel for errors; condense into a MultiError. - go item.GetSecret(collection.service.Session) - go item.Locked() - go item.Attributes() - go item.Label() - go item.Type() - go item.Created() - go item.Modified() + // TODO: use channel for errors; condense into a MultiError and switch to goroutines. + if _, err = item.GetSecret(collection.service.Session); err != nil { + return + } + if _, err = item.Locked(); err != nil { + return + } + if _, err = item.Attributes(); err != nil { + return + } + if _, err = item.Label(); err != nil { + return + } + if _, err = item.Type(); err != nil { + return + } + if _, err = item.Created(); err != nil { + return + } + if _, _, err = item.Modified(); err != nil { + return + } return } diff --git a/service_funcs.go b/service_funcs.go index 1c269bc..d28cecd 100644 --- a/service_funcs.go +++ b/service_funcs.go @@ -269,8 +269,11 @@ func (s *Service) Lock(objects ...LockableObject) (err error) { } } + // TODO: use channels and goroutines here. for _, o := range objects { - go o.Locked() + if _, err = o.Locked(); err != nil { + return + } } return @@ -491,8 +494,11 @@ func (s *Service) Unlock(objects ...LockableObject) (err error) { } } + // TODO: use channels and goroutines here. for _, o := range objects { - go o.Locked() + if _, err = o.Locked(); err != nil { + return + } } return