]> xenbits.xensource.com Git - people/gdunlap/xsatool/commitdiff
xsa: Add set-patches command to set patches for a particular xsa + version
authorGeorge Dunlap <george.dunlap@citrix.com>
Wed, 27 Sep 2017 13:40:45 +0000 (14:40 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Wed, 27 Sep 2017 13:40:45 +0000 (14:40 +0100)
...rather than editing the metadata file manually.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
README.md
main.go
xsa.go

index 0ae2b685b5eaee1c7b4c1b6f3fa20d29a2a32337..b8453c3c63e3a9b62cc10f9ac99d3d8a1a1ebe9a 100644 (file)
--- a/README.md
+++ b/README.md
@@ -260,20 +260,20 @@ Using XSA 228 as an example
 This creates an 'empty' xsa228.meta file, and the appropriate
 `-stable` and `-baseline` branches.
 
-Now edit `xsa228.meta`.  Under "Recipes", for each Xen version, there
-will be an entry called "Patches" that will be an empty array (`[ ]`).  
-Add the name of the appropriate patch in quotes inside the brackets
-for each Xen version.
+Now set the patches for each version individually:
 
-In the case of XSA 228, you'd enter `"xsa228.patch"` under both
-`"master"` and `"4.9"`, `"xsa228-4.8.patch"` under `"4.8"`, `"4.7"`,
-`"4.6"`, and so on.
+`xsatool 228 set-patches master xsa228.patch`
 
-**TODO**
+`xsatool 228 set-patches 4.9 xsa228.patch`
 
-Implement a command to do this; for example:
+`xsatool 228 set-patches 4.8 xsa228-4.8.patch`
 
-`xsatool 228 set-patches 4.9 xsa228.patch`
+...and so on.  Note that this command will only work when an XSA
+applies to only one tree; if the XSA covers more than one tree, you'll
+have to edit the metadata file by hand.
+
+**TODO** Add a way to specify multiple versions in one go; e.g.,
+`master,4.9,4.8` or something.
 
 ## Excluding a particular Xen version from an XSA
 
diff --git a/main.go b/main.go
index b92549f755cac1081bbd31a56b9792c6e640a7b9..e090f21f06e6b949f96713586187c5258890d8ca 100644 (file)
--- a/main.go
+++ b/main.go
@@ -147,6 +147,10 @@ func XsaMain(args []string) int {
                        main = MainResetBase
                        loadConfig = true
                        loadXSA = true
+               case "set-patches":
+                       main = MainSetPatches
+                       loadConfig = true
+                       loadXSA = true
                default:
                        fmt.Printf("Unknown command: %s\n", cmd)
                        return 1
diff --git a/xsa.go b/xsa.go
index 5ec4ba34dc82a2a6b21816680eb23abaeb369e04..758978f0945d5fbf5fad6d0c3e5fcaba86d71927 100644 (file)
--- a/xsa.go
+++ b/xsa.go
@@ -285,3 +285,61 @@ func MainResetBase(xsa *XSAMeta, args []string) (ret int) {
 
        return
 }
+
+// xsatool NNN set-patches version patch_glob [patch_glob ...]
+func MainSetPatches(xsa *XSAMeta, args []string) (ret int) {
+       if len(args) < 2 {
+               fmt.Printf("Not enough arguments")
+               return 1
+       }
+
+       // FIXME: Verify xenversion
+       v := XenVersion(args[0])
+
+       r := xsa.GetRecipe(v)
+       if r == nil {
+               fmt.Printf("Couldn't find recipe for xenversion %v\n", v)
+               return 1
+       }
+
+       // FIXME: Figure out what to do about this
+       if len(xsa.Trees) > 1 {
+               fmt.Printf("Error: Don't know how to handle more than one tree\n")
+               return 1
+       }
+
+       // Apply this patch to the one-and-only tree we have
+       for _, t := range xsa.Trees {
+               var err error
+               
+               xr := G.repos.XenRepos[t]
+               
+               if err = xr.MakeStableBranch(v); err != nil {
+                       fmt.Printf("Checking out stable branch for tree %v version %v: %v\n",
+                               t, v, err)
+                       return 1
+               }
+               
+               tr, prs := r.Recipes[t]
+               
+               if !prs {
+                       err = fmt.Errorf("Internal data error: no recipe for tree %s\n", t)
+                       return
+               }
+               
+               tr.Patches = append([]string(nil), args[1:]...)
+
+               xsa.dirty = true
+       }
+
+       if err := r.ApplyAll("xsa"); err != nil {
+               fmt.Printf("Error applying recipe: %v\n", err)
+               return 1
+       }
+
+       if xsa.dirty {
+               xsa.Save()
+       }
+       
+       return 0
+}