Archive a copy of config.xml when the format changes
This commit is contained in:
parent
0ebee92f7d
commit
fcf60e7f7c
@ -397,6 +397,14 @@ func syncthingMain() {
|
|||||||
l.Infof("Edit %s to taste or use the GUI\n", cfgFile)
|
l.Infof("Edit %s to taste or use the GUI\n", cfgFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cfg.Raw().OriginalVersion != config.CurrentVersion {
|
||||||
|
l.Infoln("Archiving a copy of old config file format")
|
||||||
|
// Archive a copy
|
||||||
|
osutil.Rename(cfgFile, cfgFile+fmt.Sprintf(".v%d", cfg.Raw().OriginalVersion))
|
||||||
|
// Save the new version
|
||||||
|
cfg.Save()
|
||||||
|
}
|
||||||
|
|
||||||
if len(profiler) > 0 {
|
if len(profiler) > 0 {
|
||||||
go func() {
|
go func() {
|
||||||
l.Debugln("Starting profiler on", profiler)
|
l.Debugln("Starting profiler on", profiler)
|
||||||
|
|||||||
@ -32,14 +32,17 @@ import (
|
|||||||
|
|
||||||
var l = logger.DefaultLogger
|
var l = logger.DefaultLogger
|
||||||
|
|
||||||
|
const CurrentVersion = 5
|
||||||
|
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
Version int `xml:"version,attr" default:"5"`
|
Version int `xml:"version,attr"`
|
||||||
Folders []FolderConfiguration `xml:"folder"`
|
Folders []FolderConfiguration `xml:"folder"`
|
||||||
Devices []DeviceConfiguration `xml:"device"`
|
Devices []DeviceConfiguration `xml:"device"`
|
||||||
GUI GUIConfiguration `xml:"gui"`
|
GUI GUIConfiguration `xml:"gui"`
|
||||||
Options OptionsConfiguration `xml:"options"`
|
Options OptionsConfiguration `xml:"options"`
|
||||||
XMLName xml.Name `xml:"configuration" json:"-"`
|
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_Repositories []FolderConfiguration `xml:"repository" json:"-"`
|
||||||
Deprecated_Nodes []DeviceConfiguration `xml:"node" json:"-"`
|
Deprecated_Nodes []DeviceConfiguration `xml:"node" json:"-"`
|
||||||
}
|
}
|
||||||
@ -165,6 +168,8 @@ type GUIConfiguration struct {
|
|||||||
|
|
||||||
func New(myID protocol.DeviceID) Configuration {
|
func New(myID protocol.DeviceID) Configuration {
|
||||||
var cfg Configuration
|
var cfg Configuration
|
||||||
|
cfg.Version = CurrentVersion
|
||||||
|
cfg.OriginalVersion = CurrentVersion
|
||||||
|
|
||||||
setDefaults(&cfg)
|
setDefaults(&cfg)
|
||||||
setDefaults(&cfg.Options)
|
setDefaults(&cfg.Options)
|
||||||
@ -183,6 +188,7 @@ func ReadXML(r io.Reader, myID protocol.DeviceID) (Configuration, error) {
|
|||||||
setDefaults(&cfg.GUI)
|
setDefaults(&cfg.GUI)
|
||||||
|
|
||||||
err := xml.NewDecoder(r).Decode(&cfg)
|
err := xml.NewDecoder(r).Decode(&cfg)
|
||||||
|
cfg.OriginalVersion = cfg.Version
|
||||||
|
|
||||||
cfg.prepare(myID)
|
cfg.prepare(myID)
|
||||||
return cfg, err
|
return cfg, err
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user