From: George Dunlap Date: Tue, 31 Jul 2018 11:30:48 +0000 (+0100) Subject: Use VersionsFromString for set-patches X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=c9009ae111d98164e55a972b18c3fdcb41bd8909;p=people%2Fgdunlap%2Fxsatool.git Use VersionsFromString for set-patches 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 --- diff --git a/README.md b/README.md index 1dd96bf..1f133f3 100644 --- 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 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 d4a8ae2..23eb657 100644 --- 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 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) {