diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index ee756cb8..738d5d41 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -102,7 +102,7 @@ func init() { } var ( - cfg *config.ConfigWrapper + cfg *config.Wrapper myID protocol.DeviceID confDir string logFlags = log.Ltime @@ -609,7 +609,7 @@ func syncthingMain() { os.Exit(code) } -func setupGUI(cfg *config.ConfigWrapper, m *model.Model) { +func setupGUI(cfg *config.Wrapper, m *model.Model) { opts := cfg.Options() guiCfg := overrideGUIConfig(cfg.GUI(), guiAddress, guiAuthentication, guiAPIKey) @@ -650,7 +650,7 @@ func setupGUI(cfg *config.ConfigWrapper, m *model.Model) { } } -func sanityCheckFolders(cfg *config.ConfigWrapper, m *model.Model) { +func sanityCheckFolders(cfg *config.Wrapper, m *model.Model) { nextFolder: for id, folder := range cfg.Folders() { if folder.Invalid != "" { diff --git a/internal/config/wrapper.go b/internal/config/wrapper.go index 66d17d7b..ae01f1e0 100644 --- a/internal/config/wrapper.go +++ b/internal/config/wrapper.go @@ -42,7 +42,7 @@ func (fn HandlerFunc) Changed(cfg Configuration) error { // A wrapper around a Configuration that manages loads, saves and published // notifications of changes to registered Handlers -type ConfigWrapper struct { +type Wrapper struct { cfg Configuration path string @@ -57,8 +57,8 @@ type ConfigWrapper struct { // Wrap wraps an existing Configuration structure and ties it to a file on // disk. -func Wrap(path string, cfg Configuration) *ConfigWrapper { - w := &ConfigWrapper{cfg: cfg, path: path} +func Wrap(path string, cfg Configuration) *Wrapper { + w := &Wrapper{cfg: cfg, path: path} w.replaces = make(chan Configuration) go w.Serve() return w @@ -66,7 +66,7 @@ func Wrap(path string, cfg Configuration) *ConfigWrapper { // Load loads an existing file on disk and returns a new configuration // wrapper. -func Load(path string, myID protocol.DeviceID) (*ConfigWrapper, error) { +func Load(path string, myID protocol.DeviceID) (*Wrapper, error) { fd, err := os.Open(path) if err != nil { return nil, err @@ -84,7 +84,7 @@ func Load(path string, myID protocol.DeviceID) (*ConfigWrapper, error) { // Serve handles configuration replace events and calls any interested // handlers. It is started automatically by Wrap() and Load() and should not // be run manually. -func (w *ConfigWrapper) Serve() { +func (w *Wrapper) Serve() { for cfg := range w.replaces { w.sMut.Lock() subs := w.subs @@ -97,25 +97,25 @@ func (w *ConfigWrapper) Serve() { // Stop stops the Serve() loop. Set and Replace operations will panic after a // Stop. -func (w *ConfigWrapper) Stop() { +func (w *Wrapper) Stop() { close(w.replaces) } // Subscribe registers the given handler to be called on any future // configuration changes. -func (w *ConfigWrapper) Subscribe(h Handler) { +func (w *Wrapper) Subscribe(h Handler) { w.sMut.Lock() w.subs = append(w.subs, h) w.sMut.Unlock() } // Raw returns the currently wrapped Configuration object. -func (w *ConfigWrapper) Raw() Configuration { +func (w *Wrapper) Raw() Configuration { return w.cfg } // Replace swaps the current configuration object for the given one. -func (w *ConfigWrapper) Replace(cfg Configuration) { +func (w *Wrapper) Replace(cfg Configuration) { w.mut.Lock() defer w.mut.Unlock() @@ -127,7 +127,7 @@ func (w *ConfigWrapper) Replace(cfg Configuration) { // Devices returns a map of devices. Device structures should not be changed, // other than for the purpose of updating via SetDevice(). -func (w *ConfigWrapper) Devices() map[protocol.DeviceID]DeviceConfiguration { +func (w *Wrapper) Devices() map[protocol.DeviceID]DeviceConfiguration { w.mut.Lock() defer w.mut.Unlock() if w.deviceMap == nil { @@ -141,7 +141,7 @@ func (w *ConfigWrapper) Devices() map[protocol.DeviceID]DeviceConfiguration { // SetDevice adds a new device to the configuration, or overwrites an existing // device with the same ID. -func (w *ConfigWrapper) SetDevice(dev DeviceConfiguration) { +func (w *Wrapper) SetDevice(dev DeviceConfiguration) { w.mut.Lock() defer w.mut.Unlock() @@ -161,7 +161,7 @@ func (w *ConfigWrapper) SetDevice(dev DeviceConfiguration) { // Devices returns a map of folders. Folder structures should not be changed, // other than for the purpose of updating via SetFolder(). -func (w *ConfigWrapper) Folders() map[string]FolderConfiguration { +func (w *Wrapper) Folders() map[string]FolderConfiguration { w.mut.Lock() defer w.mut.Unlock() if w.folderMap == nil { @@ -181,7 +181,7 @@ func (w *ConfigWrapper) Folders() map[string]FolderConfiguration { // SetFolder adds a new folder to the configuration, or overwrites an existing // folder with the same ID. -func (w *ConfigWrapper) SetFolder(fld FolderConfiguration) { +func (w *Wrapper) SetFolder(fld FolderConfiguration) { w.mut.Lock() defer w.mut.Unlock() @@ -200,14 +200,14 @@ func (w *ConfigWrapper) SetFolder(fld FolderConfiguration) { } // Options returns the current options configuration object. -func (w *ConfigWrapper) Options() OptionsConfiguration { +func (w *Wrapper) Options() OptionsConfiguration { w.mut.Lock() defer w.mut.Unlock() return w.cfg.Options } // SetOptions replaces the current options configuration object. -func (w *ConfigWrapper) SetOptions(opts OptionsConfiguration) { +func (w *Wrapper) SetOptions(opts OptionsConfiguration) { w.mut.Lock() defer w.mut.Unlock() w.cfg.Options = opts @@ -215,14 +215,14 @@ func (w *ConfigWrapper) SetOptions(opts OptionsConfiguration) { } // GUI returns the current GUI configuration object. -func (w *ConfigWrapper) GUI() GUIConfiguration { +func (w *Wrapper) GUI() GUIConfiguration { w.mut.Lock() defer w.mut.Unlock() return w.cfg.GUI } // SetGUI replaces the current GUI configuration object. -func (w *ConfigWrapper) SetGUI(gui GUIConfiguration) { +func (w *Wrapper) SetGUI(gui GUIConfiguration) { w.mut.Lock() defer w.mut.Unlock() w.cfg.GUI = gui @@ -230,7 +230,7 @@ func (w *ConfigWrapper) SetGUI(gui GUIConfiguration) { } // InvalidateFolder sets the invalid marker on the given folder. -func (w *ConfigWrapper) InvalidateFolder(id string, err string) { +func (w *Wrapper) InvalidateFolder(id string, err string) { w.mut.Lock() defer w.mut.Unlock() @@ -246,7 +246,7 @@ func (w *ConfigWrapper) InvalidateFolder(id string, err string) { } // Save writes the configuration to disk, and generates a ConfigSaved event. -func (w *ConfigWrapper) Save() error { +func (w *Wrapper) Save() error { fd, err := ioutil.TempFile(filepath.Dir(w.path), "cfg") if err != nil { return err diff --git a/internal/files/blockmap.go b/internal/files/blockmap.go index 618f44f4..147a1d10 100644 --- a/internal/files/blockmap.go +++ b/internal/files/blockmap.go @@ -126,7 +126,7 @@ type BlockFinder struct { mut sync.RWMutex } -func NewBlockFinder(db *leveldb.DB, cfg *config.ConfigWrapper) *BlockFinder { +func NewBlockFinder(db *leveldb.DB, cfg *config.Wrapper) *BlockFinder { if blockFinder != nil { return blockFinder } diff --git a/internal/model/model.go b/internal/model/model.go index e3faeda8..d6b58942 100644 --- a/internal/model/model.go +++ b/internal/model/model.go @@ -82,7 +82,7 @@ type service interface { } type Model struct { - cfg *config.ConfigWrapper + cfg *config.Wrapper db *leveldb.DB finder *files.BlockFinder progressEmitter *ProgressEmitter @@ -123,7 +123,7 @@ var ( // NewModel creates and starts a new model. The model starts in read-only mode, // where it sends index information to connected peers and responds to requests // for file data without altering the local folder in any way. -func NewModel(cfg *config.ConfigWrapper, deviceName, clientName, clientVersion string, db *leveldb.DB) *Model { +func NewModel(cfg *config.Wrapper, deviceName, clientName, clientVersion string, db *leveldb.DB) *Model { m := &Model{ cfg: cfg, db: db, diff --git a/internal/model/progressemitter.go b/internal/model/progressemitter.go index 203b0b1f..60df3058 100755 --- a/internal/model/progressemitter.go +++ b/internal/model/progressemitter.go @@ -38,7 +38,7 @@ type ProgressEmitter struct { // Creates a new progress emitter which emits DownloadProgress events every // interval. -func NewProgressEmitter(cfg *config.ConfigWrapper) *ProgressEmitter { +func NewProgressEmitter(cfg *config.Wrapper) *ProgressEmitter { t := &ProgressEmitter{ stop: make(chan struct{}), registry: make(map[string]*sharedPullerState),