fix(GODT-2524): Preserve old vault values

Keep the record of old vault settings alive to avoid issues when one
downgrades from a 3.1 release to a 3.0.x release.
This commit is contained in:
Leander Beernaert
2023-03-27 09:44:51 +02:00
parent 0a0bcd7b90
commit 7ba523393c
2 changed files with 27 additions and 0 deletions

View File

@ -19,6 +19,7 @@ package vault
import (
"math/rand"
"runtime"
"github.com/ProtonMail/proton-bridge/v3/internal/updater"
)
@ -44,11 +45,29 @@ type Settings struct {
FirstStart bool
MaxSyncMemory uint64
// **WARNING**: These entry can't be removed until they vault has proper migration support.
SyncWorkers int
SyncAttPool int
}
const DefaultMaxSyncMemory = 2 * 1024 * uint64(1024*1024)
func GetDefaultSyncWorkerCount() int {
const minSyncWorkers = 16
syncWorkers := runtime.NumCPU() * 4
if syncWorkers < minSyncWorkers {
syncWorkers = minSyncWorkers
}
return syncWorkers
}
func newDefaultSettings(gluonDir string) Settings {
syncWorkers := GetDefaultSyncWorkerCount()
return Settings{
GluonDir: gluonDir,
@ -70,5 +89,7 @@ func newDefaultSettings(gluonDir string) Settings {
FirstStart: true,
MaxSyncMemory: DefaultMaxSyncMemory,
SyncWorkers: syncWorkers,
SyncAttPool: syncWorkers,
}
}

View File

@ -17,6 +17,8 @@
package vault
import "github.com/ProtonMail/gluon/imap"
// UserData holds information about a single bridge user.
// The user may or may not be logged in.
type UserData struct {
@ -35,6 +37,9 @@ type UserData struct {
SyncStatus SyncStatus
EventID string
// **WARNING**: This value can't be removed until we have vault migration support.
UIDValidity map[string]imap.UID
}
type AddressMode int
@ -76,6 +81,7 @@ func newDefaultUser(userID, username, primaryEmail, authUID, authRef string, key
GluonKey: newRandomToken(32),
GluonIDs: make(map[string]string),
UIDValidity: make(map[string]imap.UID),
BridgePass: newRandomToken(16),
AddressMode: CombinedMode,