From bd2051febd0e502b6e44b695f790f96327715587 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sat, 4 Apr 2015 21:49:15 +0200 Subject: [PATCH] Remove handling for old deprecated config versions --- internal/config/config.go | 145 +----------------- internal/config/config_test.go | 2 +- internal/config/testdata/.stfolder | 0 .../testdata/deviceaddressesdynamic.xml | 14 +- .../config/testdata/deviceaddressesstatic.xml | 12 +- internal/config/testdata/overridenvalues.xml | 2 +- internal/config/testdata/v1.xml | 20 --- internal/config/testdata/v2.xml | 19 --- internal/config/testdata/v3.xml | 15 -- internal/config/testdata/v4.xml | 12 -- internal/config/testdata/versioningconfig.xml | 6 +- 11 files changed, 26 insertions(+), 221 deletions(-) delete mode 100644 internal/config/testdata/.stfolder delete mode 100755 internal/config/testdata/v1.xml delete mode 100755 internal/config/testdata/v2.xml delete mode 100755 internal/config/testdata/v3.xml delete mode 100755 internal/config/testdata/v4.xml diff --git a/internal/config/config.go b/internal/config/config.go index cc3d1e540..f689ad6c9 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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() diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 98192af98..f08d3594b 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -57,7 +57,7 @@ func TestDefaultValues(t *testing.T) { } func TestDeviceConfig(t *testing.T) { - for i := 1; i <= CurrentVersion; i++ { + for i := OldestHandledVersion; i <= CurrentVersion; i++ { os.Remove("testdata/.stfolder") wr, err := Load(fmt.Sprintf("testdata/v%d.xml", i), device1) if err != nil { diff --git a/internal/config/testdata/.stfolder b/internal/config/testdata/.stfolder deleted file mode 100644 index e69de29bb..000000000 diff --git a/internal/config/testdata/deviceaddressesdynamic.xml b/internal/config/testdata/deviceaddressesdynamic.xml index fe506c83f..c8b952607 100755 --- a/internal/config/testdata/deviceaddressesdynamic.xml +++ b/internal/config/testdata/deviceaddressesdynamic.xml @@ -1,10 +1,10 @@ - - + +
-
- - - + + + +
dynamic
-
+
diff --git a/internal/config/testdata/deviceaddressesstatic.xml b/internal/config/testdata/deviceaddressesstatic.xml index 23c159280..8f8b34058 100755 --- a/internal/config/testdata/deviceaddressesstatic.xml +++ b/internal/config/testdata/deviceaddressesstatic.xml @@ -1,14 +1,14 @@ - +
192.0.2.1
192.0.2.2
-
- + +
192.0.2.3:6070
[2001:db8::42]:4242
-
- + +
[2001:db8::44]:4444
192.0.2.4:6090
-
+
diff --git a/internal/config/testdata/overridenvalues.xml b/internal/config/testdata/overridenvalues.xml index 3742086c8..c2f72eec0 100755 --- a/internal/config/testdata/overridenvalues.xml +++ b/internal/config/testdata/overridenvalues.xml @@ -1,6 +1,6 @@ - :23000 + :23000 false syncthing.nym.se:22026 false diff --git a/internal/config/testdata/v1.xml b/internal/config/testdata/v1.xml deleted file mode 100755 index 373d842d9..000000000 --- a/internal/config/testdata/v1.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - -
a
-
- -
b
-
- -
a
-
- -
b
-
-
- - true - 600 - -
diff --git a/internal/config/testdata/v2.xml b/internal/config/testdata/v2.xml deleted file mode 100755 index 9aad846c7..000000000 --- a/internal/config/testdata/v2.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - -
a
-
- -
b
-
- - 600 - -
diff --git a/internal/config/testdata/v3.xml b/internal/config/testdata/v3.xml deleted file mode 100755 index dbb1d54d4..000000000 --- a/internal/config/testdata/v3.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - -
a
-
- -
b
-
- - 600 - -
diff --git a/internal/config/testdata/v4.xml b/internal/config/testdata/v4.xml deleted file mode 100755 index 17761d768..000000000 --- a/internal/config/testdata/v4.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - -
a
-
- -
b
-
-
diff --git a/internal/config/testdata/versioningconfig.xml b/internal/config/testdata/versioningconfig.xml index 137b84be6..b9c8c85d9 100755 --- a/internal/config/testdata/versioningconfig.xml +++ b/internal/config/testdata/versioningconfig.xml @@ -1,8 +1,8 @@ - - + + - +