Skip to content
This repository has been archived by the owner on Jun 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #13 from kainz/fix_collections_pathtypes
Browse files Browse the repository at this point in the history
Fix return type for some Collections calls/properties.
  • Loading branch information
yousefvand authored Jan 21, 2022
2 parents a628327 + 096155a commit b4e0764
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
9 changes: 7 additions & 2 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,15 @@ func (client *Client) PropertyGetCollections() ([]string, error) {
return nil, errors.New("Error getting property 'Collections': " + err.Error())
}

collections, ok := variant.Value().([]string)
collectionspaths, ok := variant.Value().([]dbus.ObjectPath)

if !ok {
return nil, fmt.Errorf("invalid 'Collections' property type. Expected '[]string', got '%T'", variant.Value())
return nil, fmt.Errorf("invalid 'Collections' property type. Expected '[]dbus.ObjectPath', got '%T'", variant.Value())
}

var collections []string
for k := range collectionspaths {
collections = append(collections, string(collectionspaths[k]))
}

sort.Strings(collections)
Expand Down
9 changes: 7 additions & 2 deletions pkg/client/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,18 @@ func (collection *Collection) PropertyGetItems() ([]string, error) {
return []string{}, fmt.Errorf("failed to read 'Items' property. Error: %v", err)
}

items, ok := variant.Value().([]string)
pathitems, ok := variant.Value().([]dbus.ObjectPath)

if !ok {
return []string{}, fmt.Errorf("expected 'Items' to be of type '[]string', got: '%T'",
return []string{}, fmt.Errorf("expected 'Items' to be of type '[]dbus.ObjectPath', got: '%T'",
variant.Value())
}

var items []string
for k := range pathitems {
items = append(items, string(pathitems[k]))
}

sort.Strings(items)

var collectionItems []string
Expand Down
4 changes: 2 additions & 2 deletions pkg/service/collection-methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,11 @@ func (collection *Collection) UpdateModified() {
// UpdatePropertyCollections updates dbus property of this collection's items
func (collection *Collection) UpdatePropertyCollectionItems() {

var items []string
var items []dbus.ObjectPath

collection.ItemsMutex.RLock()
for _, item := range collection.Items {
items = append(items, string(item.ObjectPath))
items = append(items, item.ObjectPath)
}
collection.ItemsMutex.RUnlock()

Expand Down
4 changes: 2 additions & 2 deletions pkg/service/service-methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,13 @@ func (service *Service) GetItemByPath(itemPath dbus.ObjectPath) *Item {
// UpdatePropertyCollections updates dbus properties of Service
func (s *Service) UpdatePropertyCollections() {

var collections []string
var collections []dbus.ObjectPath

s.CollectionsMutex.RLock()
defer s.CollectionsMutex.RUnlock()

for _, collection := range s.Collections {
collections = append(collections, string(collection.ObjectPath))
collections = append(collections, collection.ObjectPath)
}

PropsService.SetMust("org.freedesktop.Secret.Service",
Expand Down

0 comments on commit b4e0764

Please sign in to comment.