cmd/syncthing: Don't cache stale options in main (fixes #4474)

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4491
LGTM: imsodin, calmh
This commit is contained in:
AudriusButkevicius 2017-11-07 07:20:19 +00:00 committed by Jakob Borg
parent f6ea2a7f8e
commit 88180904f2

View File

@ -702,9 +702,7 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
}, },
} }
opts := cfg.Options() if opts := cfg.Options(); opts.WeakHashSelectionMethod == config.WeakHashAuto {
if opts.WeakHashSelectionMethod == config.WeakHashAuto {
perfWithWeakHash := cpuBench(3, 150*time.Millisecond, true) perfWithWeakHash := cpuBench(3, 150*time.Millisecond, true)
l.Infof("Hashing performance with weak hash is %.02f MB/s", perfWithWeakHash) l.Infof("Hashing performance with weak hash is %.02f MB/s", perfWithWeakHash)
perfWithoutWeakHash := cpuBench(3, 150*time.Millisecond, false) perfWithoutWeakHash := cpuBench(3, 150*time.Millisecond, false)
@ -856,13 +854,15 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
// Candidate builds always run with usage reporting. // Candidate builds always run with usage reporting.
if IsCandidate { if opts := cfg.Options(); IsCandidate {
l.Infoln("Anonymous usage reporting is always enabled for candidate releases.") l.Infoln("Anonymous usage reporting is always enabled for candidate releases.")
opts.URAccepted = usageReportVersion opts.URAccepted = usageReportVersion
cfg.SetOptions(opts)
cfg.Save()
// Unique ID will be set and config saved below if necessary. // Unique ID will be set and config saved below if necessary.
} }
if opts.URUniqueID == "" { if opts := cfg.Options(); opts.URUniqueID == "" {
opts.URUniqueID = rand.String(8) opts.URUniqueID = rand.String(8)
cfg.SetOptions(opts) cfg.SetOptions(opts)
cfg.Save() cfg.Save()
@ -871,7 +871,7 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
usageReportingSvc := newUsageReportingService(cfg, m, connectionsService) usageReportingSvc := newUsageReportingService(cfg, m, connectionsService)
mainService.Add(usageReportingSvc) mainService.Add(usageReportingSvc)
if opts.RestartOnWakeup { if opts := cfg.Options(); opts.RestartOnWakeup {
go standbyMonitor() go standbyMonitor()
} }
@ -881,7 +881,7 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
if IsCandidate && !upgrade.DisabledByCompilation && !noUpgradeFromEnv { if IsCandidate && !upgrade.DisabledByCompilation && !noUpgradeFromEnv {
l.Infoln("Automatic upgrade is always enabled for candidate releases.") l.Infoln("Automatic upgrade is always enabled for candidate releases.")
if opts.AutoUpgradeIntervalH == 0 || opts.AutoUpgradeIntervalH > 24 { if opts := cfg.Options(); opts.AutoUpgradeIntervalH == 0 || opts.AutoUpgradeIntervalH > 24 {
opts.AutoUpgradeIntervalH = 12 opts.AutoUpgradeIntervalH = 12
// Set the option into the config as well, as the auto upgrade // Set the option into the config as well, as the auto upgrade
// loop expects to read a valid interval from there. // loop expects to read a valid interval from there.
@ -892,7 +892,7 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
// not, as otherwise they cannot step off the candidate channel. // not, as otherwise they cannot step off the candidate channel.
} }
if opts.AutoUpgradeIntervalH > 0 { if opts := cfg.Options(); opts.AutoUpgradeIntervalH > 0 {
if noUpgradeFromEnv { if noUpgradeFromEnv {
l.Infof("No automatic upgrades; STNOUPGRADE environment variable defined.") l.Infof("No automatic upgrades; STNOUPGRADE environment variable defined.")
} else { } else {