Browse Source

Remove handling for old deprecated config versions

Jakob Borg 10 years ago
parent
commit
bd2051febd

+ 8 - 137
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()

+ 1 - 1
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 {

+ 0 - 0
internal/config/testdata/.stfolder


+ 7 - 7
internal/config/testdata/deviceaddressesdynamic.xml

@@ -1,10 +1,10 @@
-<configuration version="2">
-    <node id="AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ">
+<configuration version="10">
+    <device id="AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ">
         <address></address>
-    </node>
-    <node id="GYRZZQBIRNPV4T7TC52WEQYJ3TFDQW6MWDFLMU4SSSU6EMFBK2VA">
-    </node>
-    <node id="LGFPDIT7SKNNJVJZA4FC7QNCRKCE753K72BW5QD2FOZ7FRFEP57Q">
+    </device>
+    <device id="GYRZZQBIRNPV4T7TC52WEQYJ3TFDQW6MWDFLMU4SSSU6EMFBK2VA">
+    </device>
+    <device id="LGFPDIT7SKNNJVJZA4FC7QNCRKCE753K72BW5QD2FOZ7FRFEP57Q">
         <address>dynamic</address>
-    </node>
+    </device>
 </configuration>

+ 6 - 6
internal/config/testdata/deviceaddressesstatic.xml

@@ -1,14 +1,14 @@
 <configuration version="3">
-    <node id="AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ">
+    <device id="AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ">
         <address>192.0.2.1</address>
         <address>192.0.2.2</address>
-    </node>
-    <node id="GYRZZQBIRNPV4T7TC52WEQYJ3TFDQW6MWDFLMU4SSSU6EMFBK2VA">
+    </device>
+    <device id="GYRZZQBIRNPV4T7TC52WEQYJ3TFDQW6MWDFLMU4SSSU6EMFBK2VA">
         <address>192.0.2.3:6070</address>
         <address>[2001:db8::42]:4242</address>
-    </node>
-    <node id="LGFPDIT7SKNNJVJZA4FC7QNCRKCE753K72BW5QD2FOZ7FRFEP57Q">
+    </device>
+    <device id="LGFPDIT7SKNNJVJZA4FC7QNCRKCE753K72BW5QD2FOZ7FRFEP57Q">
         <address>[2001:db8::44]:4444</address>
         <address>192.0.2.4:6090</address>
-    </node>
+    </device>
 </configuration>

+ 1 - 1
internal/config/testdata/overridenvalues.xml

@@ -1,6 +1,6 @@
 <configuration version="2">
     <options>
-       <listenAddress>:23000</listenAddress>
+        <listenAddress>:23000</listenAddress>
         <allowDelete>false</allowDelete>
         <globalAnnounceServer>syncthing.nym.se:22026</globalAnnounceServer>
         <globalAnnounceEnabled>false</globalAnnounceEnabled>

+ 0 - 20
internal/config/testdata/v1.xml

@@ -1,20 +0,0 @@
-<configuration version="1">
-    <repository id="test" directory="testdata">
-        <node id="AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ" name="node one">
-            <address>a</address>
-        </node>
-        <node id="P56IOI7MZJNU2IQGDREYDM2MGTMGL3BXNPQ6W5BTBBZ4TJXZWICQ" name="node two">
-            <address>b</address>
-        </node>
-        <node id="AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ" name="node one">
-            <address>a</address>
-        </node>
-        <node id="P56IOI7MZJNU2IQGDREYDM2MGTMGL3BXNPQ6W5BTBBZ4TJXZWICQ" name="node two">
-            <address>b</address>
-        </node>
-    </repository>
-    <options>
-        <readOnly>true</readOnly>
-        <rescanIntervalS>600</rescanIntervalS>
-    </options>
-</configuration>

+ 0 - 19
internal/config/testdata/v2.xml

@@ -1,19 +0,0 @@
-<configuration version="2">
-    <repository id="test" directory="testdata" ro="true">
-        <node id="P56IOI7MZJNU2IQGDREYDM2MGTMGL3BXNPQ6W5BTBBZ4TJXZWICQ"/>
-        <node id="AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ"/>
-        <node id="C4YBIESWDUAIGU62GOSRXCRAAJDWVE3TKCPMURZE2LH5QHAF576A"/>
-        <node id="P56IOI7MZJNU2IQGDREYDM2MGTMGL3BXNPQ6W5BTBBZ4TJXZWICQ"/>
-        <node id="AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ"/>
-        <node id="C4YBIESWDUAIGU62GOSRXCRAAJDWVE3TKCPMURZE2LH5QHAF576A"/>
-    </repository>
-    <node id="AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ" name="node one">
-        <address>a</address>
-    </node>
-    <node id="P56IOI7MZJNU2IQGDREYDM2MGTMGL3BXNPQ6W5BTBBZ4TJXZWICQ" name="node two">
-        <address>b</address>
-    </node>
-    <options>
-        <rescanIntervalS>600</rescanIntervalS>
-    </options>
-</configuration>

+ 0 - 15
internal/config/testdata/v3.xml

@@ -1,15 +0,0 @@
-<configuration version="3">
-    <repository id="test" directory="testdata" ro="true" ignorePerms="false">
-        <node id="AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR" compression="false"></node>
-        <node id="P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2" compression="false"></node>
-    </repository>
-    <node id="AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR" name="node one" compression="true">
-        <address>a</address>
-    </node>
-    <node id="P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2" name="node two" compression="true">
-        <address>b</address>
-    </node>
-    <options>
-        <rescanIntervalS>600</rescanIntervalS>
-    </options>
-</configuration>

+ 0 - 12
internal/config/testdata/v4.xml

@@ -1,12 +0,0 @@
-<configuration version="4">
-    <repository id="test" directory="testdata" ro="true" ignorePerms="false" rescanIntervalS="600">
-        <node id="AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR"></node>
-        <node id="P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2"></node>
-    </repository>
-    <node id="AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR" name="node one" compression="true">
-        <address>a</address>
-    </node>
-    <node id="P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2" name="node two" compression="true">
-        <address>b</address>
-    </node>
-</configuration>

+ 3 - 3
internal/config/testdata/versioningconfig.xml

@@ -1,8 +1,8 @@
-<configuration version="2">
-    <repository id="test" directory="testdata/" ro="true">
+<configuration version="10">
+    <folder id="test" directory="testdata/" ro="true">
         <versioning type="simple">
             <param key="foo" val="bar"/>
             <param key="baz" val="quux"/>
         </versioning>
-    </repository>
+    </folder>
 </configuration>