xsa int
}
-func (r *Recipe) IsApplied(prefix string) (ok bool, err error) {
- branch, _ := r.branchName(prefix)
+const FPPath = "/tmp/xsatool-formatpatch"
+
+func (r *Recipe) MakePatches(prefix string) (err error) {
+ count := 0
+ branch, baseline := r.branchName(prefix)
+
+ // rm -rf /tmp/xsa
+ if err = os.RemoveAll(FPPath); err != nil {
+ err = fmt.Errorf("Removing temporary path: %v", err)
+ return
+ }
- if r.Xen.HasPatches() && !repos.xen.VerifyRef(branch) {
- ok = false
- return
+
+ // mkdir /tmp/xsa
+ if err = os.Mkdir(FPPath, 0777); err != nil {
+ err = fmt.Errorf("Making temporary path %s: %v\n", FPPath, err)
+ return
}
+
+ makePatches := func(xr *XenRepo, repo string) (err error) {
+ if !xr.VerifyRef(branch) {
+ return
+ }
+ if !xr.VerifyRef(baseline) {
+ fmt.Printf("WARNING: Repo %s has branch %s but no branch %s, skipping\n",
+ repo, branch, baseline)
+ return
+ }
- if r.QemuUpstream.HasPatches() && !repos.qemuu.VerifyRef(branch) {
- ok = false
- return
+ count++
+
+ path := FPPath+"/"+repo
+
+ if err = os.Mkdir(path, 0777); err != nil {
+ err = fmt.Errorf("Making temporary path %s: %v", path, err)
+ return
+ }
+
+ // git format-patch -o/tmp/xsa master
+ if _, err = xr.FormatPatch(path, baseline, branch); err != nil {
+ err = fmt.Errorf("Format-patch: %v", err)
+ return
+ }
+
+ // rm -rf ../xsa.git/xsa206-unstable && mkdir ../xsa.git/xsa206-unstable && cp /tmp/xsa/* ../xsa.git/xsa206-unstable
+
+ return
}
- if r.QemuTraditional.HasPatches() && !repos.qemut.VerifyRef(branch) {
- ok = false
- return
+ if err = makePatches(&repos.xen, "xen"); err != nil {
+ return
+ }
+ if err = makePatches(&repos.qemuu, "qemuu"); err != nil {
+ return
+ }
+ if err = makePatches(&repos.qemut, "qemut"); err != nil {
+ return
+ }
+
+ if count == 0 {
+ err = fmt.Errorf("No patches created")
+ return
+ }
+ return
+}
+
+type ErrorMissingBranch string
+
+func (s ErrorMissingBranch) Error() string {
+ return fmt.Sprintf("Missing branch: %s", s)
+}
+
+// IsApplied returns nil if the patch has been properly applied. It
+// returns an error of type ErrorMissingBranch if there's a missing
+// branch (which is aliased as a string which tells you the name of
+// the missing branch); otherwise it returns whatever error it
+// encountered when processing.
+func (r *Recipe) IsApplied(prefix string) (err error) {
+ branch, baseline := r.branchName(prefix)
+
+ check := func(xr *XenRepo) (err error) {
+ if !xr.VerifyRef(branch) {
+ return ErrorMissingBranch(branch)
+ }
+ if !xr.VerifyRef(baseline) {
+ return ErrorMissingBranch(baseline)
+ }
+ return
+ }
+
+ if r.Xen.HasPatches() {
+ if err = check(&repos.xen) ; err != nil {
+ return
+ }
+ }
+ if r.QemuUpstream.HasPatches() {
+ if err = check(&repos.qemuu) ; err != nil {
+ return
+ }
+ }
+ if r.QemuTraditional.HasPatches() {
+ if err = check(&repos.qemut) ; err != nil {
+ return
+ }
}
- ok = true
return
}
prefix := "xsa"
r := &xsa.Recipes[i]
- if ok, err := r.IsApplied(prefix); !ok {
- if err != nil {
+ if err := r.IsApplied(prefix); err != nil {
+ if _, isMissingBranch := err.(ErrorMissingBranch); !isMissingBranch {
fmt.Printf("Error checking to see if recipe has been applied: %v\n", err)
return 1
}
return 1
}
fmt.Printf("SUCCESS: %v\n", r.XenVersionFull)
- }
+ }
}
func test(xsa *XSAMeta) (ret int) {
for i := range xsa.Recipes {
+ if i == 0 {
+ continue
+ }
prefix := "test"
r := &xsa.Recipes[i]
return 0
}
-// Syncing an edited version back to xsa.git:
-// rm -rf /tmp/xsa && mkdir /tmp/xsa && git format-patch -o/tmp/xsa master && rm -rf ../xsa.git/xsa206-unstable && mkdir ../xsa.git/xsa206-unstable && cp /tmp/xsa/* ../xsa.git/xsa206-unstable
+func apply45(xsa *XSAMeta) (ret int) {
+ r := xsa.GetRecipe(XenVersion("4.5"))
+ if r == nil {
+ fmt.Printf("Couldn't get recipe")
+ return 1
+ }
+
+ if err := r.Apply("xsa"); err != nil {
+ fmt.Printf("Applying recipe: %v\n", err)
+ return 1
+ }
+ return 0
+}
func MainTest(xsanum int, args []string) (ret int) {
--- /dev/null
+package main
+
+import (
+ "fmt"
+)
+
+func MainSyncPatches(xsanum int, args []string) (ret int) {
+ err := OpenRepos()
+ if err != nil {
+ fmt.Printf("Error initializing repos: %v\n", err)
+ return 1
+ }
+
+ // FIXME
+ if len(args) == 1 && args[0] == "all" {
+ fmt.Printf("Sorry, sync-patches 'all' not implemented yet")
+ return 1
+ }
+
+ for _, v := range args {
+ // FIXME: Check XenVersion format
+ r := xsa.GetRecipe(XenVersion(v))
+ if r == nil {
+ fmt.Printf("Couldn't find recipe for XenVersion %s\n", v)
+ return 1
+ }
+
+ if err := r.MakePatches("xsa"); err != nil {
+ fmt.Printf("Making patches: %v\n", err)
+ return 1
+ }
+ }
+
+ return 0
+}