Remove handling for old deprecated config versions

This commit is contained in:
Jakob Borg
2015-04-04 21:49:15 +02:00
parent 8d41a762b6
commit bd2051febd
11 changed files with 26 additions and 221 deletions

View File

@@ -27,7 +27,10 @@ import (
var l = logger.DefaultLogger
const CurrentVersion = 10
const (
OldestHandledVersion = 5
CurrentVersion = 10
)
type Configuration struct {
Version int `xml:"version,attr" json:"version"`
@@ -38,9 +41,7 @@ type Configuration struct {
IgnoredDevices []protocol.DeviceID `xml:"ignoredDevice" json:"ignoredDevices"`
XMLName xml.Name `xml:"configuration" json:"-"`
OriginalVersion int `xml:"-" json:"-"` // The version we read from disk, before any conversion
Deprecated_Repositories []FolderConfiguration `xml:"repository" json:"-"`
Deprecated_Nodes []DeviceConfiguration `xml:"node" json:"-"`
OriginalVersion int `xml:"-" json:"-"` // The version we read from disk, before any conversion
}
type FolderConfiguration struct {
@@ -60,9 +61,6 @@ type FolderConfiguration struct {
Invalid string `xml:"-" json:"invalid"` // Set at runtime when there is an error, not saved
deviceIDs []protocol.DeviceID
Deprecated_Directory string `xml:"directory,omitempty,attr" json:"-"`
Deprecated_Nodes []FolderDeviceConfiguration `xml:"node" json:"-"`
}
func (f *FolderConfiguration) CreateMarker() error {
@@ -176,13 +174,6 @@ type OptionsConfiguration struct {
ProgressUpdateIntervalS int `xml:"progressUpdateIntervalS" json:"progressUpdateIntervalS" default:"5"`
SymlinksEnabled bool `xml:"symlinksEnabled" json:"symlinksEnabled" default:"true"`
LimitBandwidthInLan bool `xml:"limitBandwidthInLan" json:"limitBandwidthInLan" default:"false"`
Deprecated_RescanIntervalS int `xml:"rescanIntervalS,omitempty" json:"-"`
Deprecated_UREnabled bool `xml:"urEnabled,omitempty" json:"-"`
Deprecated_URDeclined bool `xml:"urDeclined,omitempty" json:"-"`
Deprecated_ReadOnly bool `xml:"readOnly,omitempty" json:"-"`
Deprecated_GUIEnabled bool `xml:"guiEnabled,omitempty" json:"-"`
Deprecated_GUIAddress string `xml:"guiAddress,omitempty" json:"-"`
}
type GUIConfiguration struct {
@@ -283,27 +274,12 @@ func (cfg *Configuration) prepare(myID protocol.DeviceID) {
}
}
if cfg.Options.Deprecated_URDeclined {
cfg.Options.URAccepted = -1
cfg.Options.URUniqueID = ""
if cfg.Version < OldestHandledVersion {
l.Warnf("Configuration version %d is deprecated. Attempting best effort conversion, but please verify manually.", cfg.Version)
}
cfg.Options.Deprecated_URDeclined = false
cfg.Options.Deprecated_UREnabled = false
// Upgrade configuration versions as appropriate
if cfg.Version == 1 {
convertV1V2(cfg)
}
if cfg.Version == 2 {
convertV2V3(cfg)
}
if cfg.Version == 3 {
convertV3V4(cfg)
}
if cfg.Version == 4 {
convertV4V5(cfg)
}
if cfg.Version == 5 {
if cfg.Version <= 5 {
convertV5V6(cfg)
}
if cfg.Version == 6 {
@@ -460,111 +436,6 @@ func convertV5V6(cfg *Configuration) {
cfg.Version = 6
}
func convertV4V5(cfg *Configuration) {
// Renamed a bunch of fields in the structs.
if cfg.Deprecated_Nodes == nil {
cfg.Deprecated_Nodes = []DeviceConfiguration{}
}
if cfg.Deprecated_Repositories == nil {
cfg.Deprecated_Repositories = []FolderConfiguration{}
}
cfg.Devices = cfg.Deprecated_Nodes
cfg.Folders = cfg.Deprecated_Repositories
for i := range cfg.Folders {
cfg.Folders[i].Path = cfg.Folders[i].Deprecated_Directory
cfg.Folders[i].Deprecated_Directory = ""
cfg.Folders[i].Devices = cfg.Folders[i].Deprecated_Nodes
cfg.Folders[i].Deprecated_Nodes = nil
}
cfg.Deprecated_Nodes = nil
cfg.Deprecated_Repositories = nil
cfg.Version = 5
}
func convertV3V4(cfg *Configuration) {
// In previous versions, rescan interval was common for each folder.
// From now, it can be set independently. We have to make sure, that after upgrade
// the individual rescan interval will be defined for every existing folder.
for i := range cfg.Deprecated_Repositories {
cfg.Deprecated_Repositories[i].RescanIntervalS = cfg.Options.Deprecated_RescanIntervalS
}
cfg.Options.Deprecated_RescanIntervalS = 0
// In previous versions, folders held full device configurations.
// Since that's the only place where device configs were in V1, we still have
// to define the deprecated fields to be able to upgrade from V1 to V4.
for i, folder := range cfg.Deprecated_Repositories {
for j := range folder.Deprecated_Nodes {
rncfg := cfg.Deprecated_Repositories[i].Deprecated_Nodes[j]
rncfg.Deprecated_Name = ""
rncfg.Deprecated_Addresses = nil
}
}
cfg.Version = 4
}
func convertV2V3(cfg *Configuration) {
// In previous versions, compression was always on. When upgrading, enable
// compression on all existing new. New devices will get compression on by
// default by the GUI.
for i := range cfg.Deprecated_Nodes {
cfg.Deprecated_Nodes[i].Compression = protocol.CompressMetadata
}
// The global discovery format and port number changed in v0.9. Having the
// default announce server but old port number is guaranteed to be legacy.
if len(cfg.Options.GlobalAnnServers) == 1 && cfg.Options.GlobalAnnServers[0] == "announce.syncthing.net:22025" {
cfg.Options.GlobalAnnServers = []string{"announce.syncthing.net:22026"}
}
cfg.Version = 3
}
func convertV1V2(cfg *Configuration) {
// Collect the list of devices.
// Replace device configs inside folders with only a reference to the
// device ID. Set all folders to read only if the global read only flag is
// set.
var devices = map[string]FolderDeviceConfiguration{}
for i, folder := range cfg.Deprecated_Repositories {
cfg.Deprecated_Repositories[i].ReadOnly = cfg.Options.Deprecated_ReadOnly
for j, device := range folder.Deprecated_Nodes {
id := device.DeviceID.String()
if _, ok := devices[id]; !ok {
devices[id] = device
}
cfg.Deprecated_Repositories[i].Deprecated_Nodes[j] = FolderDeviceConfiguration{DeviceID: device.DeviceID}
}
}
cfg.Options.Deprecated_ReadOnly = false
// Set and sort the list of devices.
for _, device := range devices {
cfg.Deprecated_Nodes = append(cfg.Deprecated_Nodes, DeviceConfiguration{
DeviceID: device.DeviceID,
Name: device.Deprecated_Name,
Addresses: device.Deprecated_Addresses,
})
}
sort.Sort(DeviceConfigurationList(cfg.Deprecated_Nodes))
// GUI
cfg.GUI.Address = cfg.Options.Deprecated_GUIAddress
cfg.GUI.Enabled = cfg.Options.Deprecated_GUIEnabled
cfg.Options.Deprecated_GUIEnabled = false
cfg.Options.Deprecated_GUIAddress = ""
cfg.Version = 2
}
func setDefaults(data interface{}) error {
s := reflect.ValueOf(data).Elem()
t := s.Type()