lib/config: Don't migrate non-HTTPS-URL discovery servers to new path (fixes #3103)

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3104
This commit is contained in:
Jakob Borg 2016-05-17 13:43:35 +00:00 committed by Audrius Butkevicius
parent 2ea22b1850
commit 922e1407c2
3 changed files with 45 additions and 11 deletions

View File

@ -14,6 +14,7 @@ import (
"io/ioutil" "io/ioutil"
"net/url" "net/url"
"os" "os"
"path"
"sort" "sort"
"strings" "strings"
@ -23,7 +24,7 @@ import (
const ( const (
OldestHandledVersion = 10 OldestHandledVersion = 10
CurrentVersion = 14 CurrentVersion = 15
MaxRescanIntervalS = 365 * 24 * 60 * 60 MaxRescanIntervalS = 365 * 24 * 60 * 60
) )
@ -201,6 +202,9 @@ func (cfg *Configuration) prepare(myID protocol.DeviceID) {
if cfg.Version == 13 { if cfg.Version == 13 {
convertV13V14(cfg) convertV13V14(cfg)
} }
if cfg.Version == 14 {
convertV14V15(cfg)
}
// Build a list of available devices // Build a list of available devices
existingDevices := make(map[protocol.DeviceID]bool) existingDevices := make(map[protocol.DeviceID]bool)
@ -254,6 +258,21 @@ func (cfg *Configuration) prepare(myID protocol.DeviceID) {
} }
} }
func convertV14V15(cfg *Configuration) {
// Undo v0.13.0 broken migration
for i, addr := range cfg.Options.GlobalAnnServers {
switch addr {
case "default-v4v2/":
cfg.Options.GlobalAnnServers[i] = "default-v4"
case "default-v6v2/":
cfg.Options.GlobalAnnServers[i] = "default-v6"
}
}
cfg.Version = 15
}
func convertV13V14(cfg *Configuration) { func convertV13V14(cfg *Configuration) {
// Not using the ignore cache is the new default. Disable it on existing // Not using the ignore cache is the new default. Disable it on existing
// configurations. // configurations.
@ -307,12 +326,13 @@ func convertV13V14(cfg *Configuration) {
var newAddrs []string var newAddrs []string
for _, addr := range cfg.Options.GlobalAnnServers { for _, addr := range cfg.Options.GlobalAnnServers {
if addr != "default" { uri, err := url.Parse(addr)
uri, err := url.Parse(addr) if err != nil {
if err != nil { // That's odd. Skip the broken address.
panic(err) continue
} }
uri.Path += "v2/" if uri.Scheme == "https" {
uri.Path = path.Join(uri.Path, "v2") + "/"
addr = uri.String() addr = uri.String()
} }

View File

@ -365,12 +365,12 @@ func TestIssue1750(t *testing.T) {
t.Errorf("%q != %q", cfg.Options().ListenAddresses[1], "tcp://:23001") t.Errorf("%q != %q", cfg.Options().ListenAddresses[1], "tcp://:23001")
} }
if cfg.Options().GlobalAnnServers[0] != "udp4://syncthing.nym.se:22026/v2/" { if cfg.Options().GlobalAnnServers[0] != "udp4://syncthing.nym.se:22026" {
t.Errorf("%q != %q", cfg.Options().GlobalAnnServers[0], "udp4://syncthing.nym.se:22026/v2/") t.Errorf("%q != %q", cfg.Options().GlobalAnnServers[0], "udp4://syncthing.nym.se:22026")
} }
if cfg.Options().GlobalAnnServers[1] != "udp4://syncthing.nym.se:22027/v2/" { if cfg.Options().GlobalAnnServers[1] != "udp4://syncthing.nym.se:22027" {
t.Errorf("%q != %q", cfg.Options().GlobalAnnServers[1], "udp4://syncthing.nym.se:22027/v2/") t.Errorf("%q != %q", cfg.Options().GlobalAnnServers[1], "udp4://syncthing.nym.se:22027")
} }
} }

14
lib/config/testdata/v15.xml vendored Normal file
View File

@ -0,0 +1,14 @@
<configuration version="15">
<folder id="test" path="testdata" type="readonly" ignorePerms="false" rescanIntervalS="600" autoNormalize="true">
<device id="AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR"></device>
<device id="P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2"></device>
<minDiskFreePct>1</minDiskFreePct>
<maxConflicts>-1</maxConflicts>
</folder>
<device id="AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR" name="node one" compression="metadata">
<address>tcp://a</address>
</device>
<device id="P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2" name="node two" compression="metadata">
<address>tcp://b</address>
</device>
</configuration>