From e7bd030a48c720e487dce1f1f97195bde06d1e58 Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Wed, 3 Oct 2018 11:54:49 -0700 Subject: [PATCH] swupd: add minversion header to MoM An upcoming improvement to swupd-client requires the minversion header to exist in the MoM in order to determine the strategy with which to update files in the update. When the minVersion argument is provided to createManifests populate a header in the MoM with this version. If no flag is provided and the previous MoM had a minversion set populate the new MoM with this version. Write the minversion to the manifest header when the minversion != 0. Since we only set minversion for the MoM the minversion will only be written to the MoM and not to bundle manifests. Signed-off-by: Matthew Johnson --- swupd/create_manifests.go | 14 ++++++++++---- swupd/manifest.go | 9 ++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/swupd/create_manifests.go b/swupd/create_manifests.go index 395ac08..2296afa 100644 --- a/swupd/create_manifests.go +++ b/swupd/create_manifests.go @@ -410,12 +410,18 @@ func CreateManifests(version uint32, minVersion uint32, format uint, statedir st newMoM := Manifest{ Name: "MoM", Header: ManifestHeader{ - Format: format, - Version: version, - Previous: lastVersion, - TimeStamp: timeStamp, + Format: format, + Version: version, + MinVersion: minVersion, + Previous: lastVersion, + TimeStamp: timeStamp, }, } + // if min-version wasn't explicitly set we need to carry the header forward + // from the old MoM + if newMoM.Header.MinVersion == 0 && oldMoM.Header.MinVersion > 0 { + newMoM.Header.MinVersion = oldMoM.Header.MinVersion + } fmt.Println("Writing manifest files...") newFull, err := newMoM.writeBundleManifests(newManifests, verOutput) diff --git a/swupd/manifest.go b/swupd/manifest.go index 97e7643..20865fd 100644 --- a/swupd/manifest.go +++ b/swupd/manifest.go @@ -49,6 +49,7 @@ type ManifestHeader struct { Format uint Version uint32 Previous uint32 + MinVersion uint32 FileCount uint32 TimeStamp time.Time ContentSize uint64 @@ -99,6 +100,11 @@ func readManifestFileHeaderLine(fields []string, m *Manifest) error { return fmt.Errorf("invalid manifest, %v", err) } m.Header.Previous = uint32(parsed) + case "minversion:": + if parsed, err = strconv.ParseUint(fields[1], 10, 32); err != nil { + return fmt.Errorf("invalid manifest, %v", err) + } + m.Header.MinVersion = uint32(parsed) case "filecount:": if parsed, err = strconv.ParseUint(fields[1], 10, 32); err != nil { return fmt.Errorf("invalid manifest, %v", err) @@ -294,7 +300,8 @@ var manifestTemplate = template.Must(template.New("manifest").Parse(` MANIFEST {{.Format}} version: {{.Version}} previous: {{.Previous}} -filecount: {{.FileCount}} +{{ if ne .MinVersion 0 }}minversion: {{.MinVersion}} +{{ end }}filecount: {{.FileCount}} timestamp: {{(.TimeStamp.Unix)}} contentsize: {{.ContentSize -}} {{range .Includes}}