chore(syncthing): ensure migrated database is closed before exiting (#10076)
After opening the database, we performed some checks, such as whether the migration had already been successfully completed. If so, the function returned immediately, and the database was not closed. --------- Co-authored-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
@@ -170,11 +170,13 @@ func TryMigrateDatabase(deleteRetention time.Duration) error {
|
|||||||
// Apparently, not a valid old database
|
// Apparently, not a valid old database
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
defer be.Close()
|
||||||
|
|
||||||
sdb, err := sqlite.OpenForMigration(locations.Get(locations.Database))
|
sdb, err := sqlite.OpenForMigration(locations.Get(locations.Database))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer sdb.Close()
|
||||||
|
|
||||||
miscDB := db.NewMiscDB(sdb)
|
miscDB := db.NewMiscDB(sdb)
|
||||||
if when, ok, err := miscDB.Time("migrated-from-leveldb-at"); err == nil && ok {
|
if when, ok, err := miscDB.Time("migrated-from-leveldb-at"); err == nil && ok {
|
||||||
@@ -265,8 +267,7 @@ func TryMigrateDatabase(deleteRetention time.Duration) error {
|
|||||||
_ = miscDB.PutTime("migrated-from-leveldb-at", time.Now())
|
_ = miscDB.PutTime("migrated-from-leveldb-at", time.Now())
|
||||||
_ = miscDB.PutString("migrated-from-leveldb-by", build.LongVersion)
|
_ = miscDB.PutString("migrated-from-leveldb-by", build.LongVersion)
|
||||||
|
|
||||||
be.Close()
|
_ = be.Close()
|
||||||
sdb.Close()
|
|
||||||
_ = os.Rename(oldDBDir, oldDBDir+"-migrated")
|
_ = os.Rename(oldDBDir, oldDBDir+"-migrated")
|
||||||
|
|
||||||
l.Infof("Migration complete, %d files and %dk blocks in %s", totFiles, totBlocks/1000, time.Since(t0).Truncate(time.Second))
|
l.Infof("Migration complete, %d files and %dk blocks in %s", totFiles, totBlocks/1000, time.Since(t0).Truncate(time.Second))
|
||||||
|
|||||||
Reference in New Issue
Block a user