mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-22 22:58:25 +00:00
Fix configInSync which is still needed
This commit is contained in:
parent
214f18cbfd
commit
5338f1cfbd
@ -346,6 +346,7 @@ func restPostConfig(m *model.Model, w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// Activate and save
|
// Activate and save
|
||||||
|
|
||||||
|
configInSync = config.ChangeRequiresRestart(cfg.Raw(), newCfg)
|
||||||
cfg.Replace(newCfg)
|
cfg.Replace(newCfg)
|
||||||
cfg.Save()
|
cfg.Save()
|
||||||
}
|
}
|
||||||
|
@ -198,40 +198,6 @@ func (cfg *Configuration) WriteXML(w io.Writer) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *Configuration) DeviceMap() map[protocol.DeviceID]DeviceConfiguration {
|
|
||||||
m := make(map[protocol.DeviceID]DeviceConfiguration, len(cfg.Devices))
|
|
||||||
for _, n := range cfg.Devices {
|
|
||||||
m[n.DeviceID] = n
|
|
||||||
}
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cfg *Configuration) GetDeviceConfiguration(deviceID protocol.DeviceID) *DeviceConfiguration {
|
|
||||||
for i, device := range cfg.Devices {
|
|
||||||
if device.DeviceID == deviceID {
|
|
||||||
return &cfg.Devices[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cfg *Configuration) GetFolderConfiguration(folderID string) *FolderConfiguration {
|
|
||||||
for i, folder := range cfg.Folders {
|
|
||||||
if folder.ID == folderID {
|
|
||||||
return &cfg.Folders[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cfg *Configuration) FolderMap() map[string]FolderConfiguration {
|
|
||||||
m := make(map[string]FolderConfiguration, len(cfg.Folders))
|
|
||||||
for _, r := range cfg.Folders {
|
|
||||||
m[r.ID] = r
|
|
||||||
}
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cfg *Configuration) prepare(myID protocol.DeviceID) {
|
func (cfg *Configuration) prepare(myID protocol.DeviceID) {
|
||||||
fillNilSlices(&cfg.Options)
|
fillNilSlices(&cfg.Options)
|
||||||
|
|
||||||
@ -317,14 +283,21 @@ func (cfg *Configuration) prepare(myID protocol.DeviceID) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure this device is present in all relevant places
|
// Ensure this device is present in all relevant places
|
||||||
me := cfg.GetDeviceConfiguration(myID)
|
myIDExists := false
|
||||||
if me == nil {
|
for _, dev := range cfg.Devices {
|
||||||
|
if dev.DeviceID == myID {
|
||||||
|
myIDExists = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !myIDExists {
|
||||||
myName, _ := os.Hostname()
|
myName, _ := os.Hostname()
|
||||||
cfg.Devices = append(cfg.Devices, DeviceConfiguration{
|
cfg.Devices = append(cfg.Devices, DeviceConfiguration{
|
||||||
DeviceID: myID,
|
DeviceID: myID,
|
||||||
Name: myName,
|
Name: myName,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(DeviceConfigurationList(cfg.Devices))
|
sort.Sort(DeviceConfigurationList(cfg.Devices))
|
||||||
// Ensure that any loose devices are not present in the wrong places
|
// Ensure that any loose devices are not present in the wrong places
|
||||||
// Ensure that there are no duplicate devices
|
// Ensure that there are no duplicate devices
|
||||||
@ -348,23 +321,17 @@ func (cfg *Configuration) prepare(myID protocol.DeviceID) {
|
|||||||
// complete restart.
|
// complete restart.
|
||||||
func ChangeRequiresRestart(from, to Configuration) bool {
|
func ChangeRequiresRestart(from, to Configuration) bool {
|
||||||
// Adding, removing or changing folders requires restart
|
// Adding, removing or changing folders requires restart
|
||||||
if len(from.Folders) != len(to.Folders) {
|
if !reflect.DeepEqual(from.Folders, to.Folders) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
fromFolders := from.FolderMap()
|
|
||||||
toFolders := to.FolderMap()
|
|
||||||
for id := range fromFolders {
|
|
||||||
if !reflect.DeepEqual(fromFolders[id], toFolders[id]) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Removing a device requires a restart. Adding one does not. Changing
|
// Removing a device requres restart
|
||||||
// address or name does not.
|
toDevs := make(map[protocol.DeviceID]bool, len(from.Devices))
|
||||||
fromDevices := from.DeviceMap()
|
for _, dev := range to.Devices {
|
||||||
toDevices := to.DeviceMap()
|
toDevs[dev.DeviceID] = true
|
||||||
for deviceID := range fromDevices {
|
}
|
||||||
if _, ok := toDevices[deviceID]; !ok {
|
for _, dev := range from.Devices {
|
||||||
|
if _, ok := toDevs[dev.DeviceID]; !ok {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -481,6 +448,7 @@ func convertV1V2(cfg *Configuration) {
|
|||||||
|
|
||||||
cfg.Version = 2
|
cfg.Version = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
func setDefaults(data interface{}) error {
|
func setDefaults(data interface{}) error {
|
||||||
s := reflect.ValueOf(data).Elem()
|
s := reflect.ValueOf(data).Elem()
|
||||||
t := s.Type()
|
t := s.Type()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user