Remove old config copies from updates

Settings -> Upkeep -> Backup & restore lists the config.json.bak-* files
that update leaves behind and removes one or all of them; they hold the
same secrets as a backup. Removing needs a signed-in user and is logged.
After a successful update only the newest 3 copies are kept, and a copy
that would overwrite an older one (version unknown, or the same version
twice) gets the time appended. The backup card now also names preshared
keys and authenticator app secrets.

The update notice uses the existing compareVersions instead of its own.
This commit is contained in:
Daniel Redetzke
2026-10-05 12:34:22 +03:00
parent 95bb95cecd
commit 32d5621cf4
8 changed files with 264 additions and 33 deletions
+3 -29
View File
@@ -8,9 +8,7 @@ import (
"io"
"log/slog"
"net/http"
"regexp"
"runtime"
"strconv"
"strings"
"sync"
"sync/atomic"
@@ -212,39 +210,15 @@ func fetchRelease(ctx context.Context, url string) (*Release, error) {
if err := json.NewDecoder(io.LimitReader(resp.Body, 1<<20)).Decode(&r); err != nil {
return nil, fmt.Errorf("unreadable answer from %s: %w", req.URL.Host, err)
}
if r.Draft || r.Prerelease || parseVersion(r.Tag) == nil {
if _, ok := compareVersions(r.Tag, r.Tag); r.Draft || r.Prerelease || !ok {
return nil, errors.New("the latest release is not a published version")
}
return &Release{Version: r.Tag, Published: r.Published, Notes: r.Body, URL: r.URL}, nil
}
var versionRe = regexp.MustCompile(`^v?(\d+)\.(\d+)\.(\d+)`)
// parseVersion reads "v0.4.0", "0.4.0" or "v0.4.0-3-gb18d16a" (a build
// after v0.4.0) as major, minor and patch, or nil.
func parseVersion(s string) []int {
m := versionRe.FindStringSubmatch(s)
if m == nil {
return nil
}
out := make([]int, 3)
for i := range out {
out[i], _ = strconv.Atoi(m[i+1])
}
return out
}
// newerVersion reports whether latest is a higher version than running.
// A running version that is not a version number is never out of date.
func newerVersion(latest, running string) bool {
l, r := parseVersion(latest), parseVersion(running)
if l == nil || r == nil {
return false
}
for i := range l {
if l[i] != r[i] {
return l[i] > r[i]
}
}
return false
c, ok := compareVersions(latest, running)
return ok && c > 0
}