MCPcopy
hub / github.com/syncthing/syncthing / CommitConfiguration

Method CommitConfiguration

lib/model/model.go:2967–3131  ·  view source on GitHub ↗
(from, to config.Configuration)

Source from the content-addressed store, hash-verified

2965}
2966
2967func (m *model) CommitConfiguration(from, to config.Configuration) bool {
2968 // TODO: This should not use reflect, and should take more care to try to handle stuff without restart.
2969
2970 // Delay processing config changes until after the initial setup
2971 <-m.started
2972
2973 // Go through the folder configs and figure out if we need to restart or not.
2974
2975 // Tracks devices affected by any configuration change to resend ClusterConfig.
2976 clusterConfigDevices := make(deviceIDSet, len(from.Devices)+len(to.Devices))
2977 closeDevices := make([]protocol.DeviceID, 0, len(to.Devices))
2978
2979 fromFolders := mapFolders(from.Folders)
2980 toFolders := mapFolders(to.Folders)
2981 for folderID, cfg := range toFolders {
2982 if _, ok := fromFolders[folderID]; !ok {
2983 // A folder was added.
2984 if cfg.Paused {
2985 slog.Info("Paused folder", cfg.LogAttr())
2986 } else {
2987 slog.Info("Adding folder", cfg.LogAttr())
2988 if err := m.newFolder(cfg, to.Options.CacheIgnoredFiles); err != nil {
2989 m.fatal(err)
2990 return true
2991 }
2992 }
2993 clusterConfigDevices.add(cfg.DeviceIDs())
2994 }
2995 }
2996
2997 removedFolders := make(map[string]struct{})
2998 for folderID, fromCfg := range fromFolders {
2999 toCfg, ok := toFolders[folderID]
3000 if !ok {
3001 // The folder was removed.
3002 m.removeFolder(fromCfg)
3003 clusterConfigDevices.add(fromCfg.DeviceIDs())
3004 removedFolders[fromCfg.ID] = struct{}{}
3005 continue
3006 }
3007
3008 if fromCfg.Paused && toCfg.Paused {
3009 continue
3010 }
3011
3012 // This folder exists on both sides. Settings might have changed.
3013 // Check if anything differs that requires a restart.
3014 if !reflect.DeepEqual(fromCfg.RequiresRestartOnly(), toCfg.RequiresRestartOnly()) || from.Options.CacheIgnoredFiles != to.Options.CacheIgnoredFiles {
3015 if err := m.restartFolder(fromCfg, toCfg, to.Options.CacheIgnoredFiles); err != nil {
3016 m.fatal(err)
3017 return true
3018 }
3019 clusterConfigDevices.add(fromCfg.DeviceIDs())
3020 if toCfg.Type != config.FolderTypeReceiveEncrypted {
3021 clusterConfigDevices.add(toCfg.DeviceIDs())
3022 } else {
3023 // If we don't have the encryption token yet, we need to drop
3024 // the connection to make the remote re-send the cluster-config

Callers

nothing calls this directly

Calls 15

newFolderMethod · 0.95
fatalMethod · 0.95
removeFolderMethod · 0.95
restartFolderMethod · 0.95
sendClusterConfigMethod · 0.95
cleanPendingMethod · 0.95
NewTypedFunction · 0.92
mapFoldersFunction · 0.85
observedDeviceSetFunction · 0.85
DeviceIDsMethod · 0.80

Tested by

no test coverage detected