]> xenbits.xensource.com Git - people/gdunlap/xsatool.git/commitdiff
XSAMeta: Store recipes in a map[XenVersion] rather than an array
authorGeorge Dunlap <george.dunlap@citrix.com>
Wed, 17 May 2017 16:22:22 +0000 (17:22 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Wed, 17 May 2017 16:22:22 +0000 (17:22 +0100)
This makes accessing it easier, and also makes the json easier for
humans to parse.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
meta.go
test.go

diff --git a/meta.go b/meta.go
index 8ea8d06e499f10aabd0e44d348fb9b605d5f67bd..b17935a24e4eb1cc574cc80d8636311560ae360c 100644 (file)
--- a/meta.go
+++ b/meta.go
@@ -193,30 +193,25 @@ func (sm *SecurityMeta) Save() (err error) {
 type XSAMeta struct {
        XSA               int
        SupportedVersions []XenVersion
-       Recipes           []Recipe
+       Recipes           map[XenVersion]*Recipe
        // Not exported
        dirty bool
 }
 
 func (m *XSAMeta) GetRecipe(v XenVersion) *Recipe {
-       for i := range m.Recipes {
-               if v == m.Recipes[i].XenVersionFull.XenVersion() {
-                       return &m.Recipes[i]
-               }
-       }
-       return nil
+       return m.Recipes[v]
 }
 
 func (m *XSAMeta) NewRecipe(fv XenVersionFull) *Recipe {
        var r Recipe
-       r.Recipes = make(map[Tree]*TreeRecipe)
 
-       r.XenVersionFull = fv
        r.xsa = m.XSA
+       r.XenVersionFull = fv
+       r.Recipes = make(map[Tree]*TreeRecipe)
 
-       m.Recipes = append(m.Recipes, r)
+       m.Recipes[fv.XenVersion()] = &r
 
-       return &m.Recipes[len(m.Recipes)-1]
+       return &r
 }
 
 func getXSAPath(xsanum int) string {
diff --git a/test.go b/test.go
index 5180b3bd249094e8707c5d8c83e34078688ed3ad..b29a4e228ba7c83ab18488047cc0d8ba0dcc4c89 100644 (file)
--- a/test.go
+++ b/test.go
@@ -9,7 +9,7 @@ import (
 func backport(xsa *XSAMeta) (ret int) {
        for i := range xsa.Recipes {
                prefix := "xsa"
-               r := &xsa.Recipes[i]
+               r := xsa.Recipes[i]
 
                if err := r.IsApplied(prefix); err != nil {
                        if _, isMissingBranch := err.(ErrorMissingBranch); !isMissingBranch {