]> xenbits.xensource.com Git - people/gdunlap/xsatool/commitdiff
Use VersionsFromString for set-patches
authorGeorge Dunlap <george.dunlap@citrix.com>
Tue, 31 Jul 2018 11:30:48 +0000 (12:30 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Tue, 31 Jul 2018 11:30:48 +0000 (12:30 +0100)
Move most of old function into a separate function, rather than
indenting into a loop, to make the diff cleaner.

While we're here fix a failure that returned 0 (the default value)
rather than 1.

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

index 1dd96bf9a6b673aae0f801fd1147f2dafe6a7cb3..1f133f3ba6a3ea01c67da89a29b8caa9640b7ff1 100644 (file)
--- a/README.md
+++ b/README.md
@@ -297,22 +297,31 @@ Using XSA 228 as an example
 This creates an 'empty' xsa228.meta file, and the appropriate
 `-stable` and `-baseline` branches.
 
-Now set the patches for each version individually:
+Then use the `set-patches` command, which looks like this:
 
-`xsatool 228 set-patches master xsa228.patch`
+`xsatool NNN set-patches <version-list> patchglob [patchglob, ...]`
 
-`xsatool 228 set-patches 4.9 xsa228.patch`
+Now set the patches for each version range:
+
+`xsatool 228 set-patches master..4.9 xsa228.patch`
 
 `xsatool 228 set-patches 4.8 xsa228-4.8.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.
+...and so on.  Or, if the same patch applies to all versions:
+
+`xsatool 272 set-patches all xsa272.patch`
+
+Or use a `glob` rather than a specific filename:
+
+`xsatool 268 set-patches 4.9..4.8 "xsa268-4.9-?.patch"`
+
+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.  Also, allow omission of the patch name
-if it matches the normal format; i.e., `set patches 4.9,4.8` would
-automatically use `xsa228-4.9.patch` for both 4.9 and 4.8.
+**TODO** Allow omission of the patch name if it matches the normal
+format; i.e., `set patches 4.9,4.8` would automatically use
+`xsa228-4.9.patch` for both 4.9 and 4.8.
 
 ## Excluding a particular Xen version from an XSA
 
diff --git a/xsa.go b/xsa.go
index d4a8ae2a3c0aa977e5cdaf7020a38012511b379a..23eb657378ca05c41a456257e10e3c61ca396bc8 100644 (file)
--- a/xsa.go
+++ b/xsa.go
@@ -316,16 +316,7 @@ 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])
-
+func setPatchesOne(xsa *XSAMeta, v XenVersion, patches []string) int {
        r := xsa.GetRecipe(v)
        if r == nil {
                fmt.Printf("Couldn't find recipe for xenversion %v\n", v)
@@ -354,10 +345,10 @@ func MainSetPatches(xsa *XSAMeta, args []string) (ret int) {
                
                if !prs {
                        err = fmt.Errorf("Internal data error: no recipe for tree %s\n", t)
-                       return
+                       return 1
                }
                
-               tr.Patches = append([]string(nil), args[1:]...)
+               tr.Patches = append([]string(nil), patches...)
 
                xsa.dirty = true
        }
@@ -367,11 +358,34 @@ func MainSetPatches(xsa *XSAMeta, args []string) (ret int) {
                return 1
        }
 
+       return 0
+       
+}
+
+// xsatool NNN set-patches <versionlist> patch_glob [patch_glob ...]
+func MainSetPatches(xsa *XSAMeta, args []string) (ret int) {
+       if len(args) < 2 {
+               fmt.Printf("Not enough arguments")
+               return 1
+       }
+
+       vers, err := VersionsFromString(args[0], xsa.SupportedVersions, nil)
+       if err != nil {
+               fmt.Printf("Error parsing versions: %v", err)
+               return
+       }
+
+       for _, v  := range vers {
+               if ret = setPatchesOne(xsa, v, args[1:]); ret != 0 {
+                       return
+               }
+       }
+
        if xsa.dirty {
                xsa.Save()
        }
-       
-       return 0
+
+       return
 }
 
 func dedupPatches(xsa *XSAMeta, from XenVersion, to XenVersion) (err error) {