From 4e5030ff388969b08b27335e1ce096a1d036542e Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Fri, 17 Feb 2023 20:14:26 +0100 Subject: [PATCH] fix output of "mox checkupdate", and specify changes to be from newest to oldest --- main.go | 10 ++++++++-- serve.go | 4 ++-- updates.go | 5 +++-- updates/updates.go | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index b663e9a..190052d 100644 --- a/main.go +++ b/main.go @@ -1634,8 +1634,14 @@ printed. if latest.After(current) { changelog, err := updates.FetchChangelog(context.Background(), changelogURL, current, changelogPubKey) xcheckf(err, "fetching changelog") - fmt.Printf("Changelog\n\n") - fmt.Println(changelog) + if len(changelog.Changes) == 0 { + log.Printf("no changes in changelog") + return + } + fmt.Println("Changelog") + for _, c := range changelog.Changes { + fmt.Println("\n" + strings.TrimSpace(c.Text)) + } } } diff --git a/serve.go b/serve.go index b73a3bb..53fffa9 100644 --- a/serve.go +++ b/serve.go @@ -235,8 +235,8 @@ requested, other TLS certificates are requested on demand. } var cl string - for i := len(changelog.Changes) - 1; i >= 0; i-- { - cl += changelog.Changes[i].Text + "\n\n" + for _, c := range changelog.Changes { + cl += c.Text + "\n\n" } a, err := store.OpenAccount(mox.Conf.Static.Postmaster.Account) diff --git a/updates.go b/updates.go index 9a89df7..3c3b39e 100644 --- a/updates.go +++ b/updates.go @@ -51,11 +51,12 @@ func cmdUpdatesAddSigned(c *cmd) { // todo future: enforce this format? sig := ed25519.Sign(privKey, buf) - changelog.Changes = append(changelog.Changes, updates.Change{ + change := updates.Change{ PubKey: privKey.Public().(ed25519.PublicKey), Sig: sig, Text: string(buf), - }) + } + changelog.Changes = append([]updates.Change{change}, changelog.Changes...) var b bytes.Buffer enc := json.NewEncoder(&b) diff --git a/updates/updates.go b/updates/updates.go index 7956a3c..08a8a44 100644 --- a/updates/updates.go +++ b/updates/updates.go @@ -76,7 +76,7 @@ type Change struct { // prevent a potential future different domain owner from notifying users about // new versions. type Changelog struct { - Changes []Change + Changes []Change // Newest first. } // Lookup looks up the updates DNS TXT record at "_updates." and returns