]> xenbits.xensource.com Git - people/gdunlap/xsatool.git/commitdiff
Recipe: Add ForEachTree method to do something for each tree
authorGeorge Dunlap <george.dunlap@citrix.com>
Wed, 17 May 2017 15:27:18 +0000 (16:27 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Wed, 17 May 2017 15:27:18 +0000 (16:27 +0100)
Have MakePatches, IsApplied, and Apply methods use it rather than
ForEachXenRepo().

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

index e6f60b852ad9430323d6095575452db39f09a9aa..91e9f16012d8f6c96e0d8cbb4b07c363a15b2b19 100644 (file)
--- a/recipe.go
+++ b/recipe.go
@@ -56,6 +56,16 @@ func cp(src, dst string) (err error) {
        return
 }
 
+func (r *Recipe) ForEachTree(f func(Tree) error) (err error) {
+       for t := range r.Recipes {
+               err = f(t)
+               if err != nil {
+                       return
+               }
+       }
+       return
+}
+
 func (r *Recipe) MakePatches(prefix string, sync bool) (err error) {
        count := 0
        branch, baseline := r.branchName(prefix)
@@ -72,10 +82,13 @@ func (r *Recipe) MakePatches(prefix string, sync bool) (err error) {
                return
        }
 
-       makePatches := func(xr *XenRepo, tree Tree) (err error) {
+       makePatches := func(tree Tree) (err error) {
+               xr := G.repos.XenRepos[tree]
+
                if !xr.VerifyRef(branch) {
                        return
                }
+
                if !xr.VerifyRef(baseline) {
                        fmt.Printf("WARNING: Repo %s has branch %s but no branch %s, skipping\n",
                                tree, branch, baseline)
@@ -100,7 +113,7 @@ func (r *Recipe) MakePatches(prefix string, sync bool) (err error) {
                return
        }
 
-       if err = ForEachXenRepo(makePatches); err != nil {
+       if err = r.ForEachTree(makePatches); err != nil {
                return
        }
 
@@ -113,7 +126,7 @@ func (r *Recipe) MakePatches(prefix string, sync bool) (err error) {
                return
        }
 
-       copyPatches := func(xr *XenRepo, tree Tree) (err error) {
+       copyPatches := func(tree Tree) (err error) {
                patchpath := FPPath + "/" + tree.String()
 
                fi, err := os.Stat(patchpath)
@@ -214,7 +227,7 @@ func (r *Recipe) MakePatches(prefix string, sync bool) (err error) {
                return
        }
 
-       if err = ForEachXenRepo(copyPatches); err != nil {
+       if err = r.ForEachTree(copyPatches); err != nil {
                return
        }
 
@@ -235,22 +248,27 @@ func (s ErrorMissingBranch) Error() string {
 func (r *Recipe) IsApplied(prefix string) (err error) {
        branch, baseline := r.branchName(prefix)
 
-       check := func(xr *XenRepo, tree Tree) (err error) {
+       check := func(tree Tree) (err error) {
                tr, prs := r.Recipes[tree]
                if !prs || !tr.HasPatches() {
                        return
                }
 
+               xr := G.repos.XenRepos[tree]
+
                if !xr.VerifyRef(branch) {
                        return ErrorMissingBranch(branch)
                }
                if !xr.VerifyRef(baseline) {
                        return ErrorMissingBranch(baseline)
                }
+
+               // FIXME: Actually check to see if something is applied
+
                return
        }
 
-       if err = ForEachXenRepo(check); err != nil {
+       if err = r.ForEachTree(check); err != nil {
                return
        }
 
@@ -310,20 +328,21 @@ func (r *Recipe) apply(xr *XenRepo, tr *TreeRecipe, prefix string) (err error) {
 }
 
 func (r *Recipe) Apply(prefix string) (err error) {
-       apply := func(xr *XenRepo, tree Tree) (err error) {
+       apply := func(tree Tree) (err error) {
                tr, prs := r.Recipes[tree]
 
-               if !prs || !tr.HasPatches() {
+               if !prs {
+                       err = fmt.Errorf("Internal data error: no recipe for tree %s\n", tree)
                        return
                }
 
+               xr := G.repos.XenRepos[tree]
+
                err = r.apply(xr, tr, prefix)
                return
        }
 
-       if err = ForEachXenRepo(apply); err != nil {
-               return
-       }
+       err = r.ForEachTree(apply)
 
        return
 }