From 112c2a7bdd198279bc87902c380e031d35a617ff Mon Sep 17 00:00:00 2001 From: Bahadir Yilmaz Date: Tue, 4 Sep 2018 21:32:25 +0300 Subject: [PATCH] cmd/main: Prevent to load syncthing along with new config file (fixes #4921) --- cmd/syncthing/main.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index 31e4a915184..b041d78aad1 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -741,6 +741,11 @@ func syncthingMain(runtimeOptions RuntimeOptions) { curParts := strings.Split(Version, "-") if prevParts[0] != curParts[0] { if prevVersion != "" { + //Check Syncthing version is wheather downgrading + l.Infof("Current Syncthing %s, Loadind %s", prevVersion, Version) + if upgrade.CompareVersions(curParts[0], prevParts[0]) == upgrade.Older || upgrade.CompareVersions(curParts[0], prevParts[0]) == upgrade.MajorOlder { + l.Infof("Current Syncthing version: %s, Loading config version: %s: (Syncthing Version Downgrade)", prevVersion, Version) + } l.Infoln("Detected upgrade from", prevVersion, "to", Version) } @@ -965,6 +970,12 @@ func loadConfigAtStartup() *config.Wrapper { } if cfg.RawCopy().OriginalVersion != config.CurrentVersion { + //check config version + if cfg.RawCopy().OriginalVersion > config.CurrentVersion { + l.Fatalf("Current config version: %d, Loading config version: %d (Config Version Conflict)", cfg.RawCopy().OriginalVersion, config.CurrentVersion) + //Config version is not compatible with installed version + os.Exit(exitError) + } err = archiveAndSaveConfig(cfg) if err != nil { l.Fatalln("Config archive:", err)