From d4b7be009c3cbae61b67a0306ff9f0d9d845bfe3 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sun, 25 Feb 2018 10:14:17 +0100 Subject: [PATCH] cmd/syncthing: Reset delta indexes on upgrade --- cmd/syncthing/main.go | 27 ++++++++++++++++++++++----- lib/db/leveldb.go | 1 + 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index 3e004f67f..1b71dd5f3 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -720,7 +720,6 @@ func syncthingMain(runtimeOptions RuntimeOptions) { dbFile := locations[locDatabase] ldb, err := db.Open(dbFile) - if err != nil { l.Fatalln("Cannot open database:", err, "- Is another copy of Syncthing already running?") } @@ -746,12 +745,30 @@ func syncthingMain(runtimeOptions RuntimeOptions) { } } - if cfg.RawCopy().OriginalVersion == 15 { - // The config version 15->16 migration is about handling ignores and - // delta indexes and requires that we drop existing indexes that - // have been incorrectly ignore filtered. + // Grab the previously running version string from the database. + + miscDB := db.NewNamespacedKV(ldb, string(db.KeyTypeMiscData)) + prevVersion, _ := miscDB.String("prevVersion") + + // Strip away prerelease/beta stuff and just compare the release + // numbers. 0.14.44 to 0.14.45-banana is an upgrade, 0.14.45-banana to + // 0.14.45-pineapple is not. + + prevParts := strings.Split(prevVersion, "-") + curParts := strings.Split(Version, "-") + if prevParts[0] != curParts[0] { + if prevVersion != "" { + l.Infoln("Detected upgrade from", prevVersion, "to", Version) + } + + // Drop delta indexes in case we've changed random stuff we + // shouldn't have. ldb.DropDeltaIndexIDs() + + // Remember the new version. + miscDB.PutString("prevVersion", Version) } + if cfg.RawCopy().OriginalVersion < 19 { // Converts old symlink types to new in the entire database. ldb.ConvertSymlinkTypes() diff --git a/lib/db/leveldb.go b/lib/db/leveldb.go index e30fd6a7b..5e8b2f810 100644 --- a/lib/db/leveldb.go +++ b/lib/db/leveldb.go @@ -26,6 +26,7 @@ const ( KeyTypeDeviceIdx KeyTypeIndexID KeyTypeFolderMeta + KeyTypeMiscData ) func (l VersionList) String() string {