2014-11-16 21:13:20 +01:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
2014-09-29 21:43:32 +02:00
|
|
|
//
|
2015-03-07 21:36:35 +01:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
2017-02-09 07:52:18 +01:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2014-06-01 22:50:14 +02:00
|
|
|
|
2014-05-15 05:40:17 +02:00
|
|
|
// Package config implements reading and writing of the syncthing configuration file.
|
2014-05-15 02:18:09 +02:00
|
|
|
package config
|
2014-03-02 23:58:14 +01:00
|
|
|
|
|
|
|
import (
|
2015-11-04 21:30:47 +01:00
|
|
|
"encoding/json"
|
2014-03-02 23:58:14 +01:00
|
|
|
"encoding/xml"
|
2016-07-02 21:38:39 +02:00
|
|
|
"fmt"
|
2014-10-06 09:25:45 +02:00
|
|
|
"io"
|
2016-05-07 00:01:56 +02:00
|
|
|
"io/ioutil"
|
2017-03-07 13:44:16 +01:00
|
|
|
"net"
|
2016-05-04 21:38:12 +02:00
|
|
|
"net/url"
|
2014-04-22 11:46:08 +02:00
|
|
|
"os"
|
2016-05-17 15:43:35 +02:00
|
|
|
"path"
|
2017-08-08 15:13:08 +02:00
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
2014-03-02 23:58:14 +01:00
|
|
|
"sort"
|
2017-03-07 13:44:16 +01:00
|
|
|
"strconv"
|
2015-03-07 20:48:53 +01:00
|
|
|
"strings"
|
2014-04-19 13:33:51 +02:00
|
|
|
|
2017-08-19 16:36:56 +02:00
|
|
|
"github.com/syncthing/syncthing/lib/fs"
|
2015-09-22 19:38:46 +02:00
|
|
|
"github.com/syncthing/syncthing/lib/protocol"
|
2016-05-26 09:02:56 +02:00
|
|
|
"github.com/syncthing/syncthing/lib/rand"
|
2017-02-04 10:45:17 +01:00
|
|
|
"github.com/syncthing/syncthing/lib/upgrade"
|
2016-03-25 21:22:29 +01:00
|
|
|
"github.com/syncthing/syncthing/lib/util"
|
2014-03-02 23:58:14 +01:00
|
|
|
)
|
|
|
|
|
2015-04-04 21:49:15 +02:00
|
|
|
const (
|
2015-10-27 11:46:33 +01:00
|
|
|
OldestHandledVersion = 10
|
2017-10-20 16:52:55 +02:00
|
|
|
CurrentVersion = 25
|
2015-06-20 20:21:05 +02:00
|
|
|
MaxRescanIntervalS = 365 * 24 * 60 * 60
|
2015-04-04 21:49:15 +02:00
|
|
|
)
|
2014-10-08 13:52:05 +02:00
|
|
|
|
2015-09-20 15:30:25 +02:00
|
|
|
var (
|
2017-03-07 13:44:16 +01:00
|
|
|
// DefaultTCPPort defines default TCP port used if the URI does not specify one, for example tcp://0.0.0.0
|
|
|
|
DefaultTCPPort = 22000
|
|
|
|
// DefaultKCPPort defines default KCP (UDP) port used if the URI does not specify one, for example kcp://0.0.0.0
|
|
|
|
DefaultKCPPort = 22020
|
2016-05-04 21:38:12 +02:00
|
|
|
// DefaultListenAddresses should be substituted when the configuration
|
2016-05-17 02:05:38 +02:00
|
|
|
// contains <listenAddress>default</listenAddress>. This is done by the
|
|
|
|
// "consumer" of the configuration as we don't want these saved to the
|
|
|
|
// config.
|
2016-05-04 21:38:12 +02:00
|
|
|
DefaultListenAddresses = []string{
|
2017-03-07 13:44:16 +01:00
|
|
|
util.Address("tcp", net.JoinHostPort("0.0.0.0", strconv.Itoa(DefaultTCPPort))),
|
2016-05-04 21:38:12 +02:00
|
|
|
"dynamic+https://relays.syncthing.net/endpoint",
|
2017-10-18 00:17:10 +02:00
|
|
|
util.Address("kcp", net.JoinHostPort("0.0.0.0", strconv.Itoa(DefaultKCPPort))),
|
2016-05-04 21:38:12 +02:00
|
|
|
}
|
|
|
|
// DefaultDiscoveryServersV4 should be substituted when the configuration
|
|
|
|
// contains <globalAnnounceServer>default-v4</globalAnnounceServer>.
|
2015-11-09 15:35:14 +01:00
|
|
|
DefaultDiscoveryServersV4 = []string{
|
2016-05-04 21:38:12 +02:00
|
|
|
"https://discovery-v4-2.syncthing.net/v2/?id=DVU36WY-H3LVZHW-E6LLFRE-YAFN5EL-HILWRYP-OC2M47J-Z4PE62Y-ADIBDQC", // 45.55.230.38, USA
|
|
|
|
"https://discovery-v4-3.syncthing.net/v2/?id=VK6HNJ3-VVMM66S-HRVWSCR-IXEHL2H-U4AQ4MW-UCPQBWX-J2L2UBK-NVZRDQZ", // 128.199.95.124, Singapore
|
2016-09-12 09:55:45 +02:00
|
|
|
"https://discovery-v4-4.syncthing.net/v2/?id=LYXKCHX-VI3NYZR-ALCJBHF-WMZYSPK-QG6QJA3-MPFYMSO-U56GTUK-NA2MIAW", // 95.85.19.244, NL
|
2015-11-09 15:35:14 +01:00
|
|
|
}
|
|
|
|
// DefaultDiscoveryServersV6 should be substituted when the configuration
|
|
|
|
// contains <globalAnnounceServer>default-v6</globalAnnounceServer>.
|
|
|
|
DefaultDiscoveryServersV6 = []string{
|
2016-05-04 21:38:12 +02:00
|
|
|
"https://discovery-v6-2.syncthing.net/v2/?id=DVU36WY-H3LVZHW-E6LLFRE-YAFN5EL-HILWRYP-OC2M47J-Z4PE62Y-ADIBDQC", // 2604:a880:800:10::182:a001, USA
|
|
|
|
"https://discovery-v6-3.syncthing.net/v2/?id=VK6HNJ3-VVMM66S-HRVWSCR-IXEHL2H-U4AQ4MW-UCPQBWX-J2L2UBK-NVZRDQZ", // 2400:6180:0:d0::d9:d001, Singapore
|
2016-09-12 11:30:06 +02:00
|
|
|
"https://discovery-v6-4.syncthing.net/v2/?id=LYXKCHX-VI3NYZR-ALCJBHF-WMZYSPK-QG6QJA3-MPFYMSO-U56GTUK-NA2MIAW", // 2a03:b0c0:0:1010::4ed:3001, NL
|
2015-09-20 15:30:25 +02:00
|
|
|
}
|
2015-11-09 15:35:14 +01:00
|
|
|
// DefaultDiscoveryServers should be substituted when the configuration
|
|
|
|
// contains <globalAnnounceServer>default</globalAnnounceServer>.
|
|
|
|
DefaultDiscoveryServers = append(DefaultDiscoveryServersV4, DefaultDiscoveryServersV6...)
|
2017-03-07 13:44:16 +01:00
|
|
|
// DefaultStunServers should be substituted when the configuration
|
|
|
|
// contains <stunServer>default</stunServer>.
|
|
|
|
DefaultStunServers = []string{
|
|
|
|
"stun.callwithus.com:3478",
|
|
|
|
"stun.counterpath.com:3478",
|
|
|
|
"stun.counterpath.net:3478",
|
|
|
|
"stun.ekiga.net:3478",
|
|
|
|
"stun.ideasip.com:3478",
|
|
|
|
"stun.internetcalls.com:3478",
|
|
|
|
"stun.schlund.de:3478",
|
|
|
|
"stun.sipgate.net:10000",
|
|
|
|
"stun.sipgate.net:3478",
|
|
|
|
"stun.voip.aebc.com:3478",
|
|
|
|
"stun.voiparound.com:3478",
|
|
|
|
"stun.voipbuster.com:3478",
|
|
|
|
"stun.voipstunt.com:3478",
|
|
|
|
"stun.voxgratia.org:3478",
|
|
|
|
"stun.xten.com:3478",
|
|
|
|
}
|
2016-01-10 16:37:31 +01:00
|
|
|
// DefaultTheme is the default and fallback theme for the web UI.
|
|
|
|
DefaultTheme = "default"
|
2015-09-20 15:30:25 +02:00
|
|
|
)
|
|
|
|
|
2015-10-27 12:04:51 +01:00
|
|
|
func New(myID protocol.DeviceID) Configuration {
|
|
|
|
var cfg Configuration
|
|
|
|
cfg.Version = CurrentVersion
|
|
|
|
cfg.OriginalVersion = CurrentVersion
|
|
|
|
|
2016-03-25 21:22:29 +01:00
|
|
|
util.SetDefaults(&cfg)
|
|
|
|
util.SetDefaults(&cfg.Options)
|
|
|
|
util.SetDefaults(&cfg.GUI)
|
2015-10-27 12:04:51 +01:00
|
|
|
|
2016-08-07 18:21:59 +02:00
|
|
|
// Can't happen.
|
|
|
|
if err := cfg.prepare(myID); err != nil {
|
|
|
|
panic("bug: error in preparing new folder: " + err.Error())
|
|
|
|
}
|
2015-10-27 12:04:51 +01:00
|
|
|
|
|
|
|
return cfg
|
|
|
|
}
|
|
|
|
|
|
|
|
func ReadXML(r io.Reader, myID protocol.DeviceID) (Configuration, error) {
|
|
|
|
var cfg Configuration
|
|
|
|
|
2016-03-25 21:22:29 +01:00
|
|
|
util.SetDefaults(&cfg)
|
|
|
|
util.SetDefaults(&cfg.Options)
|
|
|
|
util.SetDefaults(&cfg.GUI)
|
2015-10-27 12:04:51 +01:00
|
|
|
|
2016-07-02 21:38:39 +02:00
|
|
|
if err := xml.NewDecoder(r).Decode(&cfg); err != nil {
|
|
|
|
return Configuration{}, err
|
|
|
|
}
|
2015-10-27 12:04:51 +01:00
|
|
|
cfg.OriginalVersion = cfg.Version
|
|
|
|
|
2016-07-02 21:38:39 +02:00
|
|
|
if err := cfg.prepare(myID); err != nil {
|
|
|
|
return Configuration{}, err
|
|
|
|
}
|
|
|
|
return cfg, nil
|
2015-10-27 12:04:51 +01:00
|
|
|
}
|
|
|
|
|
2015-11-04 21:30:47 +01:00
|
|
|
func ReadJSON(r io.Reader, myID protocol.DeviceID) (Configuration, error) {
|
|
|
|
var cfg Configuration
|
|
|
|
|
2016-03-25 21:22:29 +01:00
|
|
|
util.SetDefaults(&cfg)
|
|
|
|
util.SetDefaults(&cfg.Options)
|
|
|
|
util.SetDefaults(&cfg.GUI)
|
2015-11-04 21:30:47 +01:00
|
|
|
|
2016-05-07 00:01:56 +02:00
|
|
|
bs, err := ioutil.ReadAll(r)
|
|
|
|
if err != nil {
|
2016-07-02 21:38:39 +02:00
|
|
|
return Configuration{}, err
|
2016-05-07 00:01:56 +02:00
|
|
|
}
|
|
|
|
|
2016-07-15 16:23:20 +02:00
|
|
|
if err := json.Unmarshal(bs, &cfg); err != nil {
|
|
|
|
return Configuration{}, err
|
|
|
|
}
|
2015-11-04 21:30:47 +01:00
|
|
|
cfg.OriginalVersion = cfg.Version
|
|
|
|
|
2016-07-02 21:38:39 +02:00
|
|
|
if err := cfg.prepare(myID); err != nil {
|
|
|
|
return Configuration{}, err
|
|
|
|
}
|
|
|
|
return cfg, nil
|
2015-11-04 21:30:47 +01:00
|
|
|
}
|
|
|
|
|
2014-03-02 23:58:14 +01:00
|
|
|
type Configuration struct {
|
2015-03-10 23:45:43 +01:00
|
|
|
Version int `xml:"version,attr" json:"version"`
|
|
|
|
Folders []FolderConfiguration `xml:"folder" json:"folders"`
|
|
|
|
Devices []DeviceConfiguration `xml:"device" json:"devices"`
|
|
|
|
GUI GUIConfiguration `xml:"gui" json:"gui"`
|
|
|
|
Options OptionsConfiguration `xml:"options" json:"options"`
|
|
|
|
IgnoredDevices []protocol.DeviceID `xml:"ignoredDevice" json:"ignoredDevices"`
|
2017-05-31 20:04:00 +02:00
|
|
|
IgnoredFolders []string `xml:"ignoredFolder" json:"ignoredFolders"`
|
2014-12-28 00:12:12 +01:00
|
|
|
XMLName xml.Name `xml:"configuration" json:"-"`
|
2014-09-28 14:22:39 +02:00
|
|
|
|
2017-05-22 21:58:33 +02:00
|
|
|
MyID protocol.DeviceID `xml:"-" json:"-"` // Provided by the instantiator.
|
|
|
|
OriginalVersion int `xml:"-" json:"-"` // The version we read from disk, before any conversion
|
2014-03-02 23:58:14 +01:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:32:10 +02:00
|
|
|
func (cfg Configuration) Copy() Configuration {
|
|
|
|
newCfg := cfg
|
2015-04-05 17:36:52 +02:00
|
|
|
|
|
|
|
// Deep copy FolderConfigurations
|
2015-04-28 22:32:10 +02:00
|
|
|
newCfg.Folders = make([]FolderConfiguration, len(cfg.Folders))
|
|
|
|
for i := range newCfg.Folders {
|
|
|
|
newCfg.Folders[i] = cfg.Folders[i].Copy()
|
2015-04-05 17:36:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Deep copy DeviceConfigurations
|
2015-04-28 22:32:10 +02:00
|
|
|
newCfg.Devices = make([]DeviceConfiguration, len(cfg.Devices))
|
|
|
|
for i := range newCfg.Devices {
|
|
|
|
newCfg.Devices[i] = cfg.Devices[i].Copy()
|
2015-04-05 17:36:52 +02:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:32:10 +02:00
|
|
|
newCfg.Options = cfg.Options.Copy()
|
2015-04-05 17:36:52 +02:00
|
|
|
|
|
|
|
// DeviceIDs are values
|
2015-04-28 22:32:10 +02:00
|
|
|
newCfg.IgnoredDevices = make([]protocol.DeviceID, len(cfg.IgnoredDevices))
|
|
|
|
copy(newCfg.IgnoredDevices, cfg.IgnoredDevices)
|
2015-04-05 17:36:52 +02:00
|
|
|
|
2017-05-31 20:04:00 +02:00
|
|
|
// FolderConfiguraion.ID is type string
|
|
|
|
newCfg.IgnoredFolders = make([]string, len(cfg.IgnoredFolders))
|
|
|
|
copy(newCfg.IgnoredFolders, cfg.IgnoredFolders)
|
|
|
|
|
2015-04-28 22:32:10 +02:00
|
|
|
return newCfg
|
2015-04-05 17:36:52 +02:00
|
|
|
}
|
|
|
|
|
2014-10-06 09:25:45 +02:00
|
|
|
func (cfg *Configuration) WriteXML(w io.Writer) error {
|
|
|
|
e := xml.NewEncoder(w)
|
|
|
|
e.Indent("", " ")
|
|
|
|
err := e.Encode(cfg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_, err = w.Write([]byte("\n"))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-07-02 21:38:39 +02:00
|
|
|
func (cfg *Configuration) prepare(myID protocol.DeviceID) error {
|
2016-08-07 18:21:59 +02:00
|
|
|
var myName string
|
|
|
|
|
2017-05-22 21:58:33 +02:00
|
|
|
cfg.MyID = myID
|
|
|
|
|
2016-08-07 18:21:59 +02:00
|
|
|
// Ensure this device is present in the config
|
|
|
|
for _, device := range cfg.Devices {
|
|
|
|
if device.DeviceID == myID {
|
|
|
|
goto found
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
myName, _ = os.Hostname()
|
|
|
|
cfg.Devices = append(cfg.Devices, DeviceConfiguration{
|
|
|
|
DeviceID: myID,
|
|
|
|
Name: myName,
|
|
|
|
})
|
|
|
|
|
|
|
|
found:
|
|
|
|
|
|
|
|
if err := cfg.clean(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that we are part of the devices
|
|
|
|
for i := range cfg.Folders {
|
|
|
|
cfg.Folders[i].Devices = ensureDevicePresent(cfg.Folders[i].Devices, myID)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cfg *Configuration) clean() error {
|
2016-03-25 21:22:29 +01:00
|
|
|
util.FillNilSlices(&cfg.Options)
|
2014-03-04 11:25:10 +01:00
|
|
|
|
2015-11-04 21:30:47 +01:00
|
|
|
// Initialize any empty slices
|
2014-09-28 13:00:38 +02:00
|
|
|
if cfg.Folders == nil {
|
|
|
|
cfg.Folders = []FolderConfiguration{}
|
2014-05-13 04:57:38 +02:00
|
|
|
}
|
2014-12-28 00:12:12 +01:00
|
|
|
if cfg.IgnoredDevices == nil {
|
|
|
|
cfg.IgnoredDevices = []protocol.DeviceID{}
|
|
|
|
}
|
2017-05-31 20:04:00 +02:00
|
|
|
if cfg.IgnoredFolders == nil {
|
|
|
|
cfg.IgnoredFolders = []string{}
|
|
|
|
}
|
2015-10-27 12:04:51 +01:00
|
|
|
if cfg.Options.AlwaysLocalNets == nil {
|
|
|
|
cfg.Options.AlwaysLocalNets = []string{}
|
|
|
|
}
|
2016-08-02 10:07:30 +02:00
|
|
|
if cfg.Options.UnackedNotificationIDs == nil {
|
|
|
|
cfg.Options.UnackedNotificationIDs = []string{}
|
|
|
|
}
|
2014-05-13 04:57:38 +02:00
|
|
|
|
2016-07-02 21:38:39 +02:00
|
|
|
// Prepare folders and check for duplicates. Duplicates are bad and
|
|
|
|
// dangerous, can't currently be resolved in the GUI, and shouldn't
|
|
|
|
// happen when configured by the GUI. We return with an error in that
|
|
|
|
// situation.
|
|
|
|
seenFolders := make(map[string]struct{})
|
2014-09-28 13:00:38 +02:00
|
|
|
for i := range cfg.Folders {
|
|
|
|
folder := &cfg.Folders[i]
|
2015-11-05 09:01:47 +01:00
|
|
|
folder.prepare()
|
2015-06-20 20:21:05 +02:00
|
|
|
|
2016-07-02 21:38:39 +02:00
|
|
|
if _, ok := seenFolders[folder.ID]; ok {
|
|
|
|
return fmt.Errorf("duplicate folder ID %q in configuration", folder.ID)
|
2014-03-29 18:53:48 +01:00
|
|
|
}
|
2016-07-02 21:38:39 +02:00
|
|
|
seenFolders[folder.ID] = struct{}{}
|
2014-03-29 18:53:48 +01:00
|
|
|
}
|
|
|
|
|
2017-06-17 20:40:28 +02:00
|
|
|
// Remove ignored folders that are anyway part of the configuration.
|
|
|
|
for i := 0; i < len(cfg.IgnoredFolders); i++ {
|
|
|
|
if _, ok := seenFolders[cfg.IgnoredFolders[i]]; ok {
|
|
|
|
cfg.IgnoredFolders = append(cfg.IgnoredFolders[:i], cfg.IgnoredFolders[i+1:]...)
|
|
|
|
i-- // IgnoredFolders[i] now points to something else, so needs to be rechecked
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-04 21:38:12 +02:00
|
|
|
cfg.Options.ListenAddresses = util.UniqueStrings(cfg.Options.ListenAddresses)
|
2016-03-25 21:22:29 +01:00
|
|
|
cfg.Options.GlobalAnnServers = util.UniqueStrings(cfg.Options.GlobalAnnServers)
|
2015-06-23 14:55:30 +02:00
|
|
|
|
2015-11-05 09:31:36 +01:00
|
|
|
if cfg.Version > 0 && cfg.Version < OldestHandledVersion {
|
2015-04-04 21:49:15 +02:00
|
|
|
l.Warnf("Configuration version %d is deprecated. Attempting best effort conversion, but please verify manually.", cfg.Version)
|
2014-06-17 23:22:19 +02:00
|
|
|
}
|
|
|
|
|
2015-03-07 20:48:53 +01:00
|
|
|
// Upgrade configuration versions as appropriate
|
2015-10-27 11:46:33 +01:00
|
|
|
if cfg.Version <= 10 {
|
2015-07-16 12:52:36 +02:00
|
|
|
convertV10V11(cfg)
|
|
|
|
}
|
2015-06-23 14:55:30 +02:00
|
|
|
if cfg.Version == 11 {
|
|
|
|
convertV11V12(cfg)
|
|
|
|
}
|
2016-04-03 21:18:16 +02:00
|
|
|
if cfg.Version == 12 {
|
|
|
|
convertV12V13(cfg)
|
|
|
|
}
|
2016-05-13 16:13:24 +02:00
|
|
|
if cfg.Version == 13 {
|
|
|
|
convertV13V14(cfg)
|
|
|
|
}
|
2016-05-17 15:43:35 +02:00
|
|
|
if cfg.Version == 14 {
|
|
|
|
convertV14V15(cfg)
|
|
|
|
}
|
2016-08-05 09:13:52 +02:00
|
|
|
if cfg.Version == 15 {
|
|
|
|
convertV15V16(cfg)
|
|
|
|
}
|
2016-11-21 18:09:29 +01:00
|
|
|
if cfg.Version == 16 {
|
|
|
|
convertV16V17(cfg)
|
|
|
|
}
|
2017-02-04 10:45:17 +01:00
|
|
|
if cfg.Version == 17 {
|
|
|
|
convertV17V18(cfg)
|
|
|
|
}
|
2017-02-07 09:34:24 +01:00
|
|
|
if cfg.Version == 18 {
|
|
|
|
convertV18V19(cfg)
|
|
|
|
}
|
2017-04-12 11:01:19 +02:00
|
|
|
if cfg.Version == 19 {
|
|
|
|
convertV19V20(cfg)
|
|
|
|
}
|
2017-08-08 15:13:08 +02:00
|
|
|
if cfg.Version == 20 {
|
|
|
|
convertV20V21(cfg)
|
|
|
|
}
|
2017-08-19 16:36:56 +02:00
|
|
|
if cfg.Version == 21 {
|
|
|
|
convertV21V22(cfg)
|
|
|
|
}
|
2017-09-02 07:52:38 +02:00
|
|
|
if cfg.Version == 22 {
|
|
|
|
convertV22V23(cfg)
|
|
|
|
}
|
2017-10-12 08:16:46 +02:00
|
|
|
if cfg.Version == 23 {
|
|
|
|
convertV23V24(cfg)
|
|
|
|
}
|
2017-10-20 16:52:55 +02:00
|
|
|
if cfg.Version == 24 {
|
|
|
|
convertV24V25(cfg)
|
|
|
|
}
|
2014-11-20 22:24:11 +01:00
|
|
|
|
2014-09-28 13:00:38 +02:00
|
|
|
// Build a list of available devices
|
|
|
|
existingDevices := make(map[protocol.DeviceID]bool)
|
|
|
|
for _, device := range cfg.Devices {
|
|
|
|
existingDevices[device.DeviceID] = true
|
2014-07-22 23:27:00 +02:00
|
|
|
}
|
|
|
|
|
2015-12-31 09:17:17 +01:00
|
|
|
// Ensure that the device list is free from duplicates
|
|
|
|
cfg.Devices = ensureNoDuplicateDevices(cfg.Devices)
|
|
|
|
|
2014-09-28 13:00:38 +02:00
|
|
|
sort.Sort(DeviceConfigurationList(cfg.Devices))
|
|
|
|
// Ensure that any loose devices are not present in the wrong places
|
|
|
|
// Ensure that there are no duplicate devices
|
2016-03-16 12:16:38 +01:00
|
|
|
// Ensure that the versioning configuration parameter map is not nil
|
2014-09-28 13:00:38 +02:00
|
|
|
for i := range cfg.Folders {
|
|
|
|
cfg.Folders[i].Devices = ensureExistingDevices(cfg.Folders[i].Devices, existingDevices)
|
2015-12-31 09:17:17 +01:00
|
|
|
cfg.Folders[i].Devices = ensureNoDuplicateFolderDevices(cfg.Folders[i].Devices)
|
2016-03-16 12:16:38 +01:00
|
|
|
if cfg.Folders[i].Versioning.Params == nil {
|
|
|
|
cfg.Folders[i].Versioning.Params = map[string]string{}
|
|
|
|
}
|
2014-09-28 13:00:38 +02:00
|
|
|
sort.Sort(FolderDeviceConfigurationList(cfg.Folders[i].Devices))
|
2014-04-22 11:46:08 +02:00
|
|
|
}
|
|
|
|
|
2014-09-28 13:00:38 +02:00
|
|
|
for i := range cfg.Devices {
|
2017-04-01 11:52:31 +02:00
|
|
|
cfg.Devices[i].prepare()
|
2014-04-22 11:46:08 +02:00
|
|
|
}
|
2014-11-18 23:57:21 +01:00
|
|
|
|
2015-03-26 13:57:27 +01:00
|
|
|
// Very short reconnection intervals are annoying
|
|
|
|
if cfg.Options.ReconnectIntervalS < 5 {
|
|
|
|
cfg.Options.ReconnectIntervalS = 5
|
|
|
|
}
|
|
|
|
|
2016-02-02 11:12:25 +01:00
|
|
|
if cfg.GUI.APIKey == "" {
|
2016-05-26 09:02:56 +02:00
|
|
|
cfg.GUI.APIKey = rand.String(32)
|
2014-12-29 13:48:26 +01:00
|
|
|
}
|
2016-07-02 21:38:39 +02:00
|
|
|
|
2016-08-05 11:29:49 +02:00
|
|
|
// The list of ignored devices should not contain any devices that have
|
|
|
|
// been manually added to the config.
|
|
|
|
newIgnoredDevices := []protocol.DeviceID{}
|
|
|
|
for _, dev := range cfg.IgnoredDevices {
|
|
|
|
if !existingDevices[dev] {
|
|
|
|
newIgnoredDevices = append(newIgnoredDevices, dev)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cfg.IgnoredDevices = newIgnoredDevices
|
|
|
|
|
2016-07-02 21:38:39 +02:00
|
|
|
return nil
|
2014-09-06 14:11:18 +02:00
|
|
|
}
|
|
|
|
|
2017-10-20 16:52:55 +02:00
|
|
|
func convertV24V25(cfg *Configuration) {
|
|
|
|
for i := range cfg.Folders {
|
|
|
|
cfg.Folders[i].FSWatcherDelayS = 10
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg.Version = 25
|
|
|
|
}
|
|
|
|
|
2017-10-12 08:16:46 +02:00
|
|
|
func convertV23V24(cfg *Configuration) {
|
|
|
|
cfg.Options.URSeen = 2
|
|
|
|
|
|
|
|
cfg.Version = 24
|
|
|
|
}
|
|
|
|
|
2017-09-02 07:52:38 +02:00
|
|
|
func convertV22V23(cfg *Configuration) {
|
|
|
|
permBits := fs.FileMode(0777)
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
// Windows has no umask so we must chose a safer set of bits to
|
|
|
|
// begin with.
|
|
|
|
permBits = 0700
|
|
|
|
}
|
|
|
|
for i := range cfg.Folders {
|
|
|
|
fs := cfg.Folders[i].Filesystem()
|
|
|
|
// Invalid config posted, or tests.
|
|
|
|
if fs == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if stat, err := fs.Stat(".stfolder"); err == nil && !stat.IsDir() {
|
|
|
|
err = fs.Remove(".stfolder")
|
|
|
|
if err == nil {
|
|
|
|
err = fs.Mkdir(".stfolder", permBits)
|
2017-09-20 08:49:04 +02:00
|
|
|
fs.Hide(".stfolder") // ignore error
|
2017-09-02 07:52:38 +02:00
|
|
|
}
|
|
|
|
if err != nil {
|
2017-09-23 15:29:55 +02:00
|
|
|
l.Infoln("Failed to upgrade folder marker:", err)
|
2017-09-02 07:52:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg.Version = 23
|
|
|
|
}
|
|
|
|
|
2017-08-19 16:36:56 +02:00
|
|
|
func convertV21V22(cfg *Configuration) {
|
|
|
|
for i := range cfg.Folders {
|
|
|
|
cfg.Folders[i].FilesystemType = fs.FilesystemTypeBasic
|
|
|
|
// Migrate to templated external versioner commands
|
|
|
|
if cfg.Folders[i].Versioning.Type == "external" {
|
|
|
|
cfg.Folders[i].Versioning.Params["command"] += " %FOLDER_PATH% %FILE_PATH%"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg.Version = 22
|
|
|
|
}
|
|
|
|
|
2017-08-08 15:13:08 +02:00
|
|
|
func convertV20V21(cfg *Configuration) {
|
|
|
|
for _, folder := range cfg.Folders {
|
2017-08-19 16:36:56 +02:00
|
|
|
if folder.FilesystemType != fs.FilesystemTypeBasic {
|
|
|
|
continue
|
|
|
|
}
|
2017-08-08 15:13:08 +02:00
|
|
|
switch folder.Versioning.Type {
|
|
|
|
case "simple", "trashcan":
|
|
|
|
// Clean out symlinks in the known place
|
2017-08-19 16:36:56 +02:00
|
|
|
cleanSymlinks(folder.Filesystem(), ".stversions")
|
2017-08-08 15:13:08 +02:00
|
|
|
case "staggered":
|
|
|
|
versionDir := folder.Versioning.Params["versionsPath"]
|
|
|
|
if versionDir == "" {
|
|
|
|
// default place
|
2017-08-19 16:36:56 +02:00
|
|
|
cleanSymlinks(folder.Filesystem(), ".stversions")
|
2017-08-08 15:13:08 +02:00
|
|
|
} else if filepath.IsAbs(versionDir) {
|
|
|
|
// absolute
|
2017-08-19 16:36:56 +02:00
|
|
|
cleanSymlinks(fs.NewFilesystem(fs.FilesystemTypeBasic, versionDir), ".")
|
2017-08-08 15:13:08 +02:00
|
|
|
} else {
|
|
|
|
// relative to folder
|
2017-08-19 16:36:56 +02:00
|
|
|
cleanSymlinks(folder.Filesystem(), versionDir)
|
2017-08-08 15:13:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg.Version = 21
|
|
|
|
}
|
|
|
|
|
2017-04-12 11:01:19 +02:00
|
|
|
func convertV19V20(cfg *Configuration) {
|
|
|
|
cfg.Options.MinHomeDiskFree = Size{Value: cfg.Options.DeprecatedMinHomeDiskFreePct, Unit: "%"}
|
|
|
|
cfg.Options.DeprecatedMinHomeDiskFreePct = 0
|
|
|
|
|
|
|
|
for i := range cfg.Folders {
|
|
|
|
cfg.Folders[i].MinDiskFree = Size{Value: cfg.Folders[i].DeprecatedMinDiskFreePct, Unit: "%"}
|
|
|
|
cfg.Folders[i].DeprecatedMinDiskFreePct = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg.Version = 20
|
|
|
|
}
|
|
|
|
|
2017-02-07 09:34:24 +01:00
|
|
|
func convertV18V19(cfg *Configuration) {
|
|
|
|
// Triggers a database tweak
|
|
|
|
cfg.Version = 19
|
|
|
|
}
|
|
|
|
|
2017-02-04 10:45:17 +01:00
|
|
|
func convertV17V18(cfg *Configuration) {
|
|
|
|
// Do channel selection for existing users. Those who have auto upgrades
|
|
|
|
// and usage reporting on default to the candidate channel. Others get
|
|
|
|
// stable.
|
|
|
|
if cfg.Options.URAccepted > 0 && cfg.Options.AutoUpgradeIntervalH > 0 {
|
|
|
|
cfg.Options.UpgradeToPreReleases = true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show a notification to explain what's going on, except if upgrades
|
|
|
|
// are disabled by compilation or environment variable in which case
|
|
|
|
// it's not relevant.
|
|
|
|
if !upgrade.DisabledByCompilation && os.Getenv("STNOUPGRADE") == "" {
|
|
|
|
cfg.Options.UnackedNotificationIDs = append(cfg.Options.UnackedNotificationIDs, "channelNotification")
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg.Version = 18
|
|
|
|
}
|
|
|
|
|
2017-02-06 11:27:11 +01:00
|
|
|
func convertV16V17(cfg *Configuration) {
|
2017-08-19 16:36:56 +02:00
|
|
|
// Fsync = true removed
|
2017-02-06 11:27:11 +01:00
|
|
|
|
|
|
|
cfg.Version = 17
|
|
|
|
}
|
|
|
|
|
|
|
|
func convertV15V16(cfg *Configuration) {
|
|
|
|
// Triggers a database tweak
|
|
|
|
cfg.Version = 16
|
|
|
|
}
|
|
|
|
|
2016-05-17 15:43:35 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2016-05-13 16:13:24 +02:00
|
|
|
func convertV13V14(cfg *Configuration) {
|
2016-04-03 21:18:16 +02:00
|
|
|
// Not using the ignore cache is the new default. Disable it on existing
|
|
|
|
// configurations.
|
|
|
|
cfg.Options.CacheIgnoredFiles = false
|
2016-05-17 02:05:38 +02:00
|
|
|
|
|
|
|
// Migrate UPnP -> NAT options
|
2016-04-10 21:36:38 +02:00
|
|
|
cfg.Options.NATEnabled = cfg.Options.DeprecatedUPnPEnabled
|
2016-05-17 02:05:38 +02:00
|
|
|
cfg.Options.DeprecatedUPnPEnabled = false
|
2016-04-10 21:36:38 +02:00
|
|
|
cfg.Options.NATLeaseM = cfg.Options.DeprecatedUPnPLeaseM
|
2016-05-17 02:05:38 +02:00
|
|
|
cfg.Options.DeprecatedUPnPLeaseM = 0
|
2016-04-10 21:36:38 +02:00
|
|
|
cfg.Options.NATRenewalM = cfg.Options.DeprecatedUPnPRenewalM
|
2016-05-17 02:05:38 +02:00
|
|
|
cfg.Options.DeprecatedUPnPRenewalM = 0
|
2016-04-10 21:36:38 +02:00
|
|
|
cfg.Options.NATTimeoutS = cfg.Options.DeprecatedUPnPTimeoutS
|
2016-05-17 02:05:38 +02:00
|
|
|
cfg.Options.DeprecatedUPnPTimeoutS = 0
|
|
|
|
|
|
|
|
// Replace the default listen address "tcp://0.0.0.0:22000" with the
|
|
|
|
// string "default", but only if we also have the default relay pool
|
|
|
|
// among the relay servers as this is implied by the new "default"
|
|
|
|
// entry.
|
|
|
|
hasDefault := false
|
|
|
|
for _, raddr := range cfg.Options.DeprecatedRelayServers {
|
|
|
|
if raddr == "dynamic+https://relays.syncthing.net/endpoint" {
|
|
|
|
for i, addr := range cfg.Options.ListenAddresses {
|
|
|
|
if addr == "tcp://0.0.0.0:22000" {
|
|
|
|
cfg.Options.ListenAddresses[i] = "default"
|
|
|
|
hasDefault = true
|
|
|
|
break
|
|
|
|
}
|
2016-05-04 21:38:12 +02:00
|
|
|
}
|
2016-05-17 02:05:38 +02:00
|
|
|
break
|
2016-05-04 21:38:12 +02:00
|
|
|
}
|
2016-05-17 02:05:38 +02:00
|
|
|
}
|
2016-05-04 21:38:12 +02:00
|
|
|
|
2016-05-17 02:05:38 +02:00
|
|
|
// Copy relay addresses into listen addresses.
|
|
|
|
for _, addr := range cfg.Options.DeprecatedRelayServers {
|
|
|
|
if hasDefault && addr == "dynamic+https://relays.syncthing.net/endpoint" {
|
|
|
|
// Skip the default relay address if we already have the
|
|
|
|
// "default" entry in the list.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if addr == "" {
|
|
|
|
continue
|
2016-05-04 21:38:12 +02:00
|
|
|
}
|
2016-05-17 02:05:38 +02:00
|
|
|
cfg.Options.ListenAddresses = append(cfg.Options.ListenAddresses, addr)
|
2016-05-04 21:38:12 +02:00
|
|
|
}
|
2016-05-17 02:05:38 +02:00
|
|
|
|
2016-05-04 21:38:12 +02:00
|
|
|
cfg.Options.DeprecatedRelayServers = nil
|
|
|
|
|
2016-05-17 02:05:38 +02:00
|
|
|
// For consistency
|
|
|
|
sort.Strings(cfg.Options.ListenAddresses)
|
|
|
|
|
2016-05-04 21:38:12 +02:00
|
|
|
var newAddrs []string
|
|
|
|
for _, addr := range cfg.Options.GlobalAnnServers {
|
2016-05-17 15:43:35 +02:00
|
|
|
uri, err := url.Parse(addr)
|
|
|
|
if err != nil {
|
|
|
|
// That's odd. Skip the broken address.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if uri.Scheme == "https" {
|
|
|
|
uri.Path = path.Join(uri.Path, "v2") + "/"
|
2016-05-04 21:38:12 +02:00
|
|
|
addr = uri.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
newAddrs = append(newAddrs, addr)
|
|
|
|
}
|
|
|
|
cfg.Options.GlobalAnnServers = newAddrs
|
|
|
|
|
2016-05-04 12:47:33 +02:00
|
|
|
for i, fcfg := range cfg.Folders {
|
|
|
|
if fcfg.DeprecatedReadOnly {
|
2016-12-16 23:23:35 +01:00
|
|
|
cfg.Folders[i].Type = FolderTypeSendOnly
|
2016-05-04 12:47:33 +02:00
|
|
|
} else {
|
2016-12-16 23:23:35 +01:00
|
|
|
cfg.Folders[i].Type = FolderTypeSendReceive
|
2016-05-04 12:47:33 +02:00
|
|
|
}
|
|
|
|
cfg.Folders[i].DeprecatedReadOnly = false
|
|
|
|
}
|
2016-05-15 00:03:07 +02:00
|
|
|
// v0.13-beta already had config version 13 but did not get the new URL
|
|
|
|
if cfg.Options.ReleasesURL == "https://api.github.com/repos/syncthing/syncthing/releases?per_page=30" {
|
|
|
|
cfg.Options.ReleasesURL = "https://upgrades.syncthing.net/meta.json"
|
|
|
|
}
|
2016-05-13 11:17:10 +02:00
|
|
|
|
2016-05-13 16:13:24 +02:00
|
|
|
cfg.Version = 14
|
|
|
|
}
|
|
|
|
|
|
|
|
func convertV12V13(cfg *Configuration) {
|
2016-05-13 11:17:10 +02:00
|
|
|
if cfg.Options.ReleasesURL == "https://api.github.com/repos/syncthing/syncthing/releases?per_page=30" {
|
|
|
|
cfg.Options.ReleasesURL = "https://upgrades.syncthing.net/meta.json"
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg.Version = 13
|
2016-04-03 21:18:16 +02:00
|
|
|
}
|
|
|
|
|
2015-06-23 14:55:30 +02:00
|
|
|
func convertV11V12(cfg *Configuration) {
|
|
|
|
// Change listen address schema
|
2016-05-04 21:38:12 +02:00
|
|
|
for i, addr := range cfg.Options.ListenAddresses {
|
2015-06-23 14:55:30 +02:00
|
|
|
if len(addr) > 0 && !strings.HasPrefix(addr, "tcp://") {
|
2016-05-04 21:38:12 +02:00
|
|
|
cfg.Options.ListenAddresses[i] = util.Address("tcp", addr)
|
2015-06-23 14:55:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, device := range cfg.Devices {
|
|
|
|
for j, addr := range device.Addresses {
|
|
|
|
if addr != "dynamic" && addr != "" {
|
2016-03-25 21:22:29 +01:00
|
|
|
cfg.Devices[i].Addresses[j] = util.Address("tcp", addr)
|
2015-06-23 14:55:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use new discovery server
|
2015-09-20 15:30:25 +02:00
|
|
|
var newDiscoServers []string
|
|
|
|
var useDefault bool
|
|
|
|
for _, addr := range cfg.Options.GlobalAnnServers {
|
2015-06-23 14:55:30 +02:00
|
|
|
if addr == "udp4://announce.syncthing.net:22026" {
|
2015-09-20 15:30:25 +02:00
|
|
|
useDefault = true
|
2015-06-23 14:55:30 +02:00
|
|
|
} else if addr == "udp6://announce-v6.syncthing.net:22026" {
|
2015-09-20 15:30:25 +02:00
|
|
|
useDefault = true
|
|
|
|
} else {
|
|
|
|
newDiscoServers = append(newDiscoServers, addr)
|
2015-06-23 14:55:30 +02:00
|
|
|
}
|
|
|
|
}
|
2015-09-20 15:30:25 +02:00
|
|
|
if useDefault {
|
|
|
|
newDiscoServers = append(newDiscoServers, "default")
|
|
|
|
}
|
|
|
|
cfg.Options.GlobalAnnServers = newDiscoServers
|
2015-06-23 14:55:30 +02:00
|
|
|
|
2015-08-23 14:59:38 +02:00
|
|
|
// Use new multicast group
|
|
|
|
if cfg.Options.LocalAnnMCAddr == "[ff32::5222]:21026" {
|
|
|
|
cfg.Options.LocalAnnMCAddr = "[ff12::8384]:21027"
|
|
|
|
}
|
|
|
|
|
2015-08-27 16:04:13 +02:00
|
|
|
// Use new local discovery port
|
|
|
|
if cfg.Options.LocalAnnPort == 21025 {
|
|
|
|
cfg.Options.LocalAnnPort = 21027
|
|
|
|
}
|
|
|
|
|
2015-10-13 21:50:58 +02:00
|
|
|
// Set MaxConflicts to unlimited
|
|
|
|
for i := range cfg.Folders {
|
|
|
|
cfg.Folders[i].MaxConflicts = -1
|
|
|
|
}
|
|
|
|
|
2015-06-23 14:55:30 +02:00
|
|
|
cfg.Version = 12
|
|
|
|
}
|
|
|
|
|
2015-10-13 21:50:58 +02:00
|
|
|
func convertV10V11(cfg *Configuration) {
|
|
|
|
// Set minimum disk free of existing folders to 1%
|
|
|
|
for i := range cfg.Folders {
|
2017-04-12 11:01:19 +02:00
|
|
|
cfg.Folders[i].DeprecatedMinDiskFreePct = 1
|
2015-10-13 21:50:58 +02:00
|
|
|
}
|
|
|
|
cfg.Version = 11
|
|
|
|
}
|
|
|
|
|
2014-09-28 13:00:38 +02:00
|
|
|
func ensureDevicePresent(devices []FolderDeviceConfiguration, myID protocol.DeviceID) []FolderDeviceConfiguration {
|
|
|
|
for _, device := range devices {
|
|
|
|
if device.DeviceID.Equals(myID) {
|
|
|
|
return devices
|
2014-03-02 23:58:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-28 13:00:38 +02:00
|
|
|
devices = append(devices, FolderDeviceConfiguration{
|
|
|
|
DeviceID: myID,
|
2014-07-28 01:20:36 +02:00
|
|
|
})
|
2014-03-02 23:58:14 +01:00
|
|
|
|
2014-09-28 13:00:38 +02:00
|
|
|
return devices
|
2014-03-02 23:58:14 +01:00
|
|
|
}
|
2014-07-22 23:27:00 +02:00
|
|
|
|
2014-09-28 13:00:38 +02:00
|
|
|
func ensureExistingDevices(devices []FolderDeviceConfiguration, existingDevices map[protocol.DeviceID]bool) []FolderDeviceConfiguration {
|
|
|
|
count := len(devices)
|
2014-07-22 23:27:00 +02:00
|
|
|
i := 0
|
2014-07-28 01:08:15 +02:00
|
|
|
loop:
|
|
|
|
for i < count {
|
2014-09-28 13:00:38 +02:00
|
|
|
if _, ok := existingDevices[devices[i].DeviceID]; !ok {
|
|
|
|
devices[i] = devices[count-1]
|
2014-07-28 01:08:15 +02:00
|
|
|
count--
|
|
|
|
continue loop
|
2014-07-22 23:27:00 +02:00
|
|
|
}
|
2014-07-28 01:08:15 +02:00
|
|
|
i++
|
2014-07-22 23:27:00 +02:00
|
|
|
}
|
2014-09-28 13:00:38 +02:00
|
|
|
return devices[0:count]
|
2014-07-22 23:27:00 +02:00
|
|
|
}
|
2014-07-28 01:15:16 +02:00
|
|
|
|
2015-12-31 09:17:17 +01:00
|
|
|
func ensureNoDuplicateFolderDevices(devices []FolderDeviceConfiguration) []FolderDeviceConfiguration {
|
|
|
|
count := len(devices)
|
|
|
|
i := 0
|
|
|
|
seenDevices := make(map[protocol.DeviceID]bool)
|
|
|
|
loop:
|
|
|
|
for i < count {
|
|
|
|
id := devices[i].DeviceID
|
|
|
|
if _, ok := seenDevices[id]; ok {
|
|
|
|
devices[i] = devices[count-1]
|
|
|
|
count--
|
|
|
|
continue loop
|
|
|
|
}
|
|
|
|
seenDevices[id] = true
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
return devices[0:count]
|
|
|
|
}
|
|
|
|
|
|
|
|
func ensureNoDuplicateDevices(devices []DeviceConfiguration) []DeviceConfiguration {
|
2014-09-28 13:00:38 +02:00
|
|
|
count := len(devices)
|
2014-07-28 01:15:16 +02:00
|
|
|
i := 0
|
2014-09-28 13:00:38 +02:00
|
|
|
seenDevices := make(map[protocol.DeviceID]bool)
|
2014-07-28 01:15:16 +02:00
|
|
|
loop:
|
|
|
|
for i < count {
|
2014-09-28 13:00:38 +02:00
|
|
|
id := devices[i].DeviceID
|
|
|
|
if _, ok := seenDevices[id]; ok {
|
|
|
|
devices[i] = devices[count-1]
|
2014-07-28 01:15:16 +02:00
|
|
|
count--
|
|
|
|
continue loop
|
|
|
|
}
|
2014-09-28 13:00:38 +02:00
|
|
|
seenDevices[id] = true
|
2014-07-28 01:15:16 +02:00
|
|
|
i++
|
|
|
|
}
|
2014-09-28 13:00:38 +02:00
|
|
|
return devices[0:count]
|
2014-07-28 01:15:16 +02:00
|
|
|
}
|
2017-08-08 15:13:08 +02:00
|
|
|
|
2017-08-19 16:36:56 +02:00
|
|
|
func cleanSymlinks(filesystem fs.Filesystem, dir string) {
|
2017-08-08 15:13:08 +02:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
// We don't do symlinks on Windows. Additionally, there may
|
|
|
|
// be things that look like symlinks that are not, which we
|
|
|
|
// should leave alone. Deduplicated files, for example.
|
|
|
|
return
|
|
|
|
}
|
2017-08-19 16:36:56 +02:00
|
|
|
filesystem.Walk(dir, func(path string, info fs.FileInfo, err error) error {
|
2017-08-08 15:13:08 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-08-19 16:36:56 +02:00
|
|
|
if info.IsSymlink() {
|
2017-08-08 15:13:08 +02:00
|
|
|
l.Infoln("Removing incorrectly versioned symlink", path)
|
2017-08-19 16:36:56 +02:00
|
|
|
filesystem.Remove(path)
|
|
|
|
return fs.SkipDir
|
2017-08-08 15:13:08 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|