}
if loadXSA {
- switch xsanum {
- case 206:
- xsa = XSAMeta{
- XSA: 206,
- SupportedVersions: []XenVersion{"master", "4.8", "4.7", "4.6", "4.5", "4.4"},
- Recipes: []Recipe{
- Recipe{
- XenVersionFull: XenVersionFull("master"),
- Xen: TreeRecipe{ Patches: []string{"xsa206-unstable/*.patch"} },
- },
- Recipe{
- XenVersionFull: XenVersionFull("4.8.0"),
- Xen: TreeRecipe{ Patches: []string{"xsa206-4.8/*.patch"} },
- },
- Recipe{
- XenVersionFull: XenVersionFull("4.7.2"),
- Xen: TreeRecipe{ Patches: []string{"xsa206-4.7/*.patch"} },
- },
- Recipe{
- XenVersionFull: XenVersionFull("4.6.5"),
- Xen: TreeRecipe{ Patches: []string{"xsa206-4.6/*.patch"} },
- },
- Recipe{
- XenVersionFull: XenVersionFull("4.5.5"),
- Xen: TreeRecipe{ Patches: []string{"xsa206-4.5/*.patch"} },
- },
- Recipe{
- XenVersionFull: XenVersionFull("4.4.4"),
- Xen: TreeRecipe{ Patches: []string{"xsa206-4.4/*.patch"} },
- },
- },
- }
- case 212:
- xsa = XSAMeta{
- XSA: 212,
- SupportedVersions: []XenVersion{"master", "4.8", "4.7", "4.6", "4.5", "4.4"},
- Recipes: []Recipe{
- Recipe{
- XenVersionFull: XenVersionFull("master"),
- Xen: TreeRecipe{ Patches: []string{"xsa212-unstable.patch"} },
- },
- Recipe{
- XenVersionFull: XenVersionFull("4.8.0"),
- Xen: TreeRecipe{ Patches: []string{"xsa212-unstable.patch"} },
- },
- Recipe{
- XenVersionFull: XenVersionFull("4.7.2"),
- Xen: TreeRecipe{ Patches: []string{"xsa212-unstable.patch"} },
- },
- Recipe{
- XenVersionFull: XenVersionFull("4.6.5"),
- Xen: TreeRecipe{ Patches: []string{"xsa212-unstable.patch"} },
- },
- Recipe{
- XenVersionFull: XenVersionFull("4.5.5"),
- Xen: TreeRecipe{ Patches: []string{"xsa212-unstable.patch"} },
- },
- Recipe{
- XenVersionFull: XenVersionFull("4.4.4"),
- Xen: TreeRecipe{ Patches: []string{"xsa212-unstable.patch"} },
- },
- },
- }
-
- default:
- fmt.Printf("No recipe for xsa %d\n", xsanum)
- os.Exit(-1)
+ err = xsa.Load(xsanum)
+ if err != nil {
+ fmt.Printf("Loading xsa%d metadata: %v\n",
+ err)
+ os.Exit(1)
}
-
- xsa.Normalize()
}
os.Exit(main(xsanum, args))
XSA int
SupportedVersions []XenVersion
Recipes []Recipe
+ // Not exported
+ dirty bool
}
func (m *XSAMeta) GetRecipe(v XenVersion) (*Recipe) {
m.Recipes[i].xsa = m.XSA
}
}
+
+func (xm *XSAMeta) Load(xsanum int) (err error) {
+ if config.Tool.GetXSAPath() == "" {
+ return fmt.Errorf("Tool config not loaded")
+ }
+
+ filename := fmt.Sprintf("%s/xsa%d.meta",
+ config.Tool.GetXSAPath(), xsanum)
+
+ b, err := ioutil.ReadFile(filename)
+ if err != nil {
+ if os.IsNotExist(err) {
+ // No problem if the file doesn't exist; just use the null config
+ xm.XSA = xsanum
+ return nil
+ } else {
+ return fmt.Errorf("Opening global metadata file %s: %v\n", filename, err)
+ }
+ }
+
+ err = json.Unmarshal(b, xm)
+ if err != nil {
+ return fmt.Errorf("Unmarshalling metadata: %v\n", err)
+ }
+
+ if xm.XSA != xsanum {
+ return fmt.Errorf("Invalid input: Expecting xsa %d, got %d\n",
+ xsanum, xm.XSA)
+ }
+ return
+}
+
+func (xm *XSAMeta) Save() (err error) {
+ if config.Tool.GetXSAPath() == "" {
+ return fmt.Errorf("Tool config not loaded")
+ }
+
+ b, err := json.MarshalIndent(*xm, "", " ")
+ if err != nil {
+ return fmt.Errorf("Marshalling config: %v", err)
+ }
+
+ filename := config.Tool.GetXSAPath() + "/" + GlobalMetaFilename
+ err = ioutil.WriteFile(filename, b, 0666)
+ if err != nil {
+ return fmt.Errorf("Writing config: %v", err)
+ }
+
+ xm.dirty = false
+
+ return
+}