Merge pull request #803 from stb-tester/deterministic-stanza-WriteTo

Stanza.WriteTo: Sort extra fields alphabetically
This commit is contained in:
Andrey Smirnov
2019-01-25 17:34:34 +03:00
committed by GitHub
2 changed files with 12 additions and 2 deletions

View File

@@ -34,3 +34,4 @@ List of contributors, in chronological order:
* Maximilian Stein (https://github.com/steinymity)
* Strajan Sebastian (https://github.com/strajansebastian)
* Artem Smirnov (https://github.com/urpylka)
* William Manley (https://github.com/wmanley)

View File

@@ -4,6 +4,7 @@ import (
"bufio"
"errors"
"io"
"sort"
"strings"
"unicode"
)
@@ -182,8 +183,16 @@ func (s Stanza) WriteTo(w *bufio.Writer, isSource, isRelease, isInstaller bool)
// no extra fields in installer
if !isInstaller {
for field, value := range s {
err := writeField(w, field, value, isRelease)
// Print extra fields in deterministic order (alphabetical)
keys := make([]string, len(s))
i := 0
for field := range s {
keys[i] = field
i++
}
sort.Strings(keys)
for _, field := range keys {
err := writeField(w, field, s[field], isRelease)
if err != nil {
return err
}