cmd/syncthing: Handle pre-releases with zero auto upgrade interval (fixes #4090)

This commit is contained in:
Jakob Borg 2017-04-10 15:56:52 +02:00
parent ae4206f362
commit c205fdd77e
1 changed files with 15 additions and 3 deletions

View File

@ -923,6 +923,10 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
l.Infoln("Automatic upgrade is always enabled for candidate releases.")
if opts.AutoUpgradeIntervalH == 0 || opts.AutoUpgradeIntervalH > 24 {
opts.AutoUpgradeIntervalH = 12
// Set the option into the config as well, as the auto upgrade
// loop expects to read a valid interval from there.
cfg.SetOptions(opts)
cfg.Save()
}
// We don't tweak the user's choice of upgrading to pre-releases or
// not, as otherwise they cannot step off the candidate channel.
@ -1241,7 +1245,15 @@ func autoUpgrade(cfg *config.Wrapper) {
l.Infof("Connected to device %s with a newer version (current %q < remote %q). Checking for upgrades.", data["id"], Version, data["clientVersion"])
case <-timer.C:
}
opts := cfg.Options()
checkInterval := time.Duration(opts.AutoUpgradeIntervalH) * time.Hour
if checkInterval < time.Hour {
// We shouldn't be here if AutoUpgradeIntervalH < 1, but for
// safety's sake.
checkInterval = time.Hour
}
rel, err := upgrade.LatestRelease(opts.ReleasesURL, Version, opts.UpgradeToPreReleases)
if err == upgrade.ErrUpgradeUnsupported {
events.Default.Unsubscribe(sub)
@ -1251,13 +1263,13 @@ func autoUpgrade(cfg *config.Wrapper) {
// Don't complain too loudly here; we might simply not have
// internet connectivity, or the upgrade server might be down.
l.Infoln("Automatic upgrade:", err)
timer.Reset(time.Duration(cfg.Options().AutoUpgradeIntervalH) * time.Hour)
timer.Reset(checkInterval)
continue
}
if upgrade.CompareVersions(rel.Tag, Version) != upgrade.Newer {
// Skip equal, older or majorly newer (incompatible) versions
timer.Reset(time.Duration(cfg.Options().AutoUpgradeIntervalH) * time.Hour)
timer.Reset(checkInterval)
continue
}
@ -1265,7 +1277,7 @@ func autoUpgrade(cfg *config.Wrapper) {
err = upgrade.To(rel)
if err != nil {
l.Warnln("Automatic upgrade:", err)
timer.Reset(time.Duration(cfg.Options().AutoUpgradeIntervalH) * time.Hour)
timer.Reset(checkInterval)
continue
}
events.Default.Unsubscribe(sub)