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 <matthew.johnson@intel.com>
This commit is contained in:
Matthew Johnson
2018-10-05 11:23:12 -07:00
committed by tmarcu
parent dd49c0cf53
commit e7bd030a48
2 changed files with 18 additions and 5 deletions
+10 -4
View File
@@ -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)
+8 -1
View File
@@ -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}}