config.ConfigWrapper -> config.Wrapper

This commit is contained in:
Jakob Borg 2014-12-08 16:39:11 +01:00
parent 9d07aa006d
commit febeed3277
5 changed files with 26 additions and 26 deletions

View File

@ -102,7 +102,7 @@ func init() {
} }
var ( var (
cfg *config.ConfigWrapper cfg *config.Wrapper
myID protocol.DeviceID myID protocol.DeviceID
confDir string confDir string
logFlags = log.Ltime logFlags = log.Ltime
@ -609,7 +609,7 @@ func syncthingMain() {
os.Exit(code) os.Exit(code)
} }
func setupGUI(cfg *config.ConfigWrapper, m *model.Model) { func setupGUI(cfg *config.Wrapper, m *model.Model) {
opts := cfg.Options() opts := cfg.Options()
guiCfg := overrideGUIConfig(cfg.GUI(), guiAddress, guiAuthentication, guiAPIKey) 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: nextFolder:
for id, folder := range cfg.Folders() { for id, folder := range cfg.Folders() {
if folder.Invalid != "" { if folder.Invalid != "" {

View File

@ -42,7 +42,7 @@ func (fn HandlerFunc) Changed(cfg Configuration) error {
// A wrapper around a Configuration that manages loads, saves and published // A wrapper around a Configuration that manages loads, saves and published
// notifications of changes to registered Handlers // notifications of changes to registered Handlers
type ConfigWrapper struct { type Wrapper struct {
cfg Configuration cfg Configuration
path string path string
@ -57,8 +57,8 @@ type ConfigWrapper struct {
// Wrap wraps an existing Configuration structure and ties it to a file on // Wrap wraps an existing Configuration structure and ties it to a file on
// disk. // disk.
func Wrap(path string, cfg Configuration) *ConfigWrapper { func Wrap(path string, cfg Configuration) *Wrapper {
w := &ConfigWrapper{cfg: cfg, path: path} w := &Wrapper{cfg: cfg, path: path}
w.replaces = make(chan Configuration) w.replaces = make(chan Configuration)
go w.Serve() go w.Serve()
return w 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 // Load loads an existing file on disk and returns a new configuration
// wrapper. // wrapper.
func Load(path string, myID protocol.DeviceID) (*ConfigWrapper, error) { func Load(path string, myID protocol.DeviceID) (*Wrapper, error) {
fd, err := os.Open(path) fd, err := os.Open(path)
if err != nil { if err != nil {
return nil, err 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 // Serve handles configuration replace events and calls any interested
// handlers. It is started automatically by Wrap() and Load() and should not // handlers. It is started automatically by Wrap() and Load() and should not
// be run manually. // be run manually.
func (w *ConfigWrapper) Serve() { func (w *Wrapper) Serve() {
for cfg := range w.replaces { for cfg := range w.replaces {
w.sMut.Lock() w.sMut.Lock()
subs := w.subs 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 stops the Serve() loop. Set and Replace operations will panic after a
// Stop. // Stop.
func (w *ConfigWrapper) Stop() { func (w *Wrapper) Stop() {
close(w.replaces) close(w.replaces)
} }
// Subscribe registers the given handler to be called on any future // Subscribe registers the given handler to be called on any future
// configuration changes. // configuration changes.
func (w *ConfigWrapper) Subscribe(h Handler) { func (w *Wrapper) Subscribe(h Handler) {
w.sMut.Lock() w.sMut.Lock()
w.subs = append(w.subs, h) w.subs = append(w.subs, h)
w.sMut.Unlock() w.sMut.Unlock()
} }
// Raw returns the currently wrapped Configuration object. // Raw returns the currently wrapped Configuration object.
func (w *ConfigWrapper) Raw() Configuration { func (w *Wrapper) Raw() Configuration {
return w.cfg return w.cfg
} }
// Replace swaps the current configuration object for the given one. // 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() w.mut.Lock()
defer w.mut.Unlock() 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, // Devices returns a map of devices. Device structures should not be changed,
// other than for the purpose of updating via SetDevice(). // 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() w.mut.Lock()
defer w.mut.Unlock() defer w.mut.Unlock()
if w.deviceMap == nil { 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 // SetDevice adds a new device to the configuration, or overwrites an existing
// device with the same ID. // device with the same ID.
func (w *ConfigWrapper) SetDevice(dev DeviceConfiguration) { func (w *Wrapper) SetDevice(dev DeviceConfiguration) {
w.mut.Lock() w.mut.Lock()
defer w.mut.Unlock() 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, // Devices returns a map of folders. Folder structures should not be changed,
// other than for the purpose of updating via SetFolder(). // 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() w.mut.Lock()
defer w.mut.Unlock() defer w.mut.Unlock()
if w.folderMap == nil { 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 // SetFolder adds a new folder to the configuration, or overwrites an existing
// folder with the same ID. // folder with the same ID.
func (w *ConfigWrapper) SetFolder(fld FolderConfiguration) { func (w *Wrapper) SetFolder(fld FolderConfiguration) {
w.mut.Lock() w.mut.Lock()
defer w.mut.Unlock() defer w.mut.Unlock()
@ -200,14 +200,14 @@ func (w *ConfigWrapper) SetFolder(fld FolderConfiguration) {
} }
// Options returns the current options configuration object. // Options returns the current options configuration object.
func (w *ConfigWrapper) Options() OptionsConfiguration { func (w *Wrapper) Options() OptionsConfiguration {
w.mut.Lock() w.mut.Lock()
defer w.mut.Unlock() defer w.mut.Unlock()
return w.cfg.Options return w.cfg.Options
} }
// SetOptions replaces the current options configuration object. // SetOptions replaces the current options configuration object.
func (w *ConfigWrapper) SetOptions(opts OptionsConfiguration) { func (w *Wrapper) SetOptions(opts OptionsConfiguration) {
w.mut.Lock() w.mut.Lock()
defer w.mut.Unlock() defer w.mut.Unlock()
w.cfg.Options = opts w.cfg.Options = opts
@ -215,14 +215,14 @@ func (w *ConfigWrapper) SetOptions(opts OptionsConfiguration) {
} }
// GUI returns the current GUI configuration object. // GUI returns the current GUI configuration object.
func (w *ConfigWrapper) GUI() GUIConfiguration { func (w *Wrapper) GUI() GUIConfiguration {
w.mut.Lock() w.mut.Lock()
defer w.mut.Unlock() defer w.mut.Unlock()
return w.cfg.GUI return w.cfg.GUI
} }
// SetGUI replaces the current GUI configuration object. // SetGUI replaces the current GUI configuration object.
func (w *ConfigWrapper) SetGUI(gui GUIConfiguration) { func (w *Wrapper) SetGUI(gui GUIConfiguration) {
w.mut.Lock() w.mut.Lock()
defer w.mut.Unlock() defer w.mut.Unlock()
w.cfg.GUI = gui w.cfg.GUI = gui
@ -230,7 +230,7 @@ func (w *ConfigWrapper) SetGUI(gui GUIConfiguration) {
} }
// InvalidateFolder sets the invalid marker on the given folder. // 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() w.mut.Lock()
defer w.mut.Unlock() 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. // 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") fd, err := ioutil.TempFile(filepath.Dir(w.path), "cfg")
if err != nil { if err != nil {
return err return err

View File

@ -126,7 +126,7 @@ type BlockFinder struct {
mut sync.RWMutex mut sync.RWMutex
} }
func NewBlockFinder(db *leveldb.DB, cfg *config.ConfigWrapper) *BlockFinder { func NewBlockFinder(db *leveldb.DB, cfg *config.Wrapper) *BlockFinder {
if blockFinder != nil { if blockFinder != nil {
return blockFinder return blockFinder
} }

View File

@ -82,7 +82,7 @@ type service interface {
} }
type Model struct { type Model struct {
cfg *config.ConfigWrapper cfg *config.Wrapper
db *leveldb.DB db *leveldb.DB
finder *files.BlockFinder finder *files.BlockFinder
progressEmitter *ProgressEmitter progressEmitter *ProgressEmitter
@ -123,7 +123,7 @@ var (
// NewModel creates and starts a new model. The model starts in read-only mode, // 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 // where it sends index information to connected peers and responds to requests
// for file data without altering the local folder in any way. // 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{ m := &Model{
cfg: cfg, cfg: cfg,
db: db, db: db,

View File

@ -38,7 +38,7 @@ type ProgressEmitter struct {
// Creates a new progress emitter which emits DownloadProgress events every // Creates a new progress emitter which emits DownloadProgress events every
// interval. // interval.
func NewProgressEmitter(cfg *config.ConfigWrapper) *ProgressEmitter { func NewProgressEmitter(cfg *config.Wrapper) *ProgressEmitter {
t := &ProgressEmitter{ t := &ProgressEmitter{
stop: make(chan struct{}), stop: make(chan struct{}),
registry: make(map[string]*sharedPullerState), registry: make(map[string]*sharedPullerState),