commit 2cda9680208ab8e7618ca7be298ba8971f03e10f
parent 38efa3ab63d419415875bba87e1b15a7b3ce9dcd
Author: Sean Enck <sean@ttypty.com>
Date: Sat, 4 Mar 2023 17:17:43 -0500
use generic map implementation for this
Diffstat:
3 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/go.mod b/go.mod
@@ -4,7 +4,7 @@ go 1.19
require (
github.com/aymanbagabas/go-osc52 v1.2.2
- github.com/enckse/pgl v0.0.0-20230304211614-6a4d061229b0
+ github.com/enckse/pgl v0.0.0-20230304221611-426e9e4c7e88
github.com/pquerna/otp v1.4.0
github.com/tobischo/gokeepasslib/v3 v3.5.0
mvdan.cc/sh/v3 v3.6.0
diff --git a/go.sum b/go.sum
@@ -9,8 +9,8 @@ github.com/boombuler/barcode v1.0.1 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyX
github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
-github.com/enckse/pgl v0.0.0-20230304211614-6a4d061229b0 h1:dAFFmvOlaNVh0OsdqBEKLAEybijhmtu3TEAgvagx02w=
-github.com/enckse/pgl v0.0.0-20230304211614-6a4d061229b0/go.mod h1:r5bqGzwqnJIeY6UbGT5u38keJ5+ZySlsWeaYYzdBhMg=
+github.com/enckse/pgl v0.0.0-20230304221611-426e9e4c7e88 h1:hiEvVPHGcFo+jhLfaTaW+A68xo5hjlXFAoM29JzpAXw=
+github.com/enckse/pgl v0.0.0-20230304221611-426e9e4c7e88/go.mod h1:r5bqGzwqnJIeY6UbGT5u38keJ5+ZySlsWeaYYzdBhMg=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
diff --git a/internal/backend/query.go b/internal/backend/query.go
@@ -8,6 +8,7 @@ import (
"sort"
"strings"
+ "github.com/enckse/pgl/maps"
"github.com/tobischo/gokeepasslib/v3"
)
@@ -70,8 +71,7 @@ func (t *Transaction) QueryCallback(args QueryOptions) ([]QueryEntity, error) {
if args.Mode == noneMode {
return nil, errors.New("no query mode specified")
}
- var keys []string
- entities := make(map[string]QueryEntity)
+ entities := maps.KeyedMap[string, QueryEntity]{}
isSort := args.Mode != ExactMode
decrypt := args.Values != BlankValue
err := t.act(func(ctx Context) error {
@@ -102,8 +102,7 @@ func (t *Transaction) QueryCallback(args QueryOptions) ([]QueryEntity, error) {
}
}
}
- keys = append(keys, path)
- entities[path] = QueryEntity{backing: entry}
+ entities.Add(path, QueryEntity{backing: entry})
})
if decrypt {
return ctx.db.UnlockProtectedEntries()
@@ -113,6 +112,7 @@ func (t *Transaction) QueryCallback(args QueryOptions) ([]QueryEntity, error) {
if err != nil {
return nil, err
}
+ keys := entities.Keys()
if isSort {
sort.Strings(keys)
}
@@ -120,7 +120,10 @@ func (t *Transaction) QueryCallback(args QueryOptions) ([]QueryEntity, error) {
for _, k := range keys {
entity := QueryEntity{Path: k}
if args.Values != BlankValue {
- e := entities[k]
+ e, ok := entities.Get(k)
+ if !ok {
+ return nil, errors.New("failed to read entity back from map")
+ }
val := getValue(e.backing, notesKey)
if strings.TrimSpace(val) == "" {
val = e.backing.GetPassword()