lib/config: Raw() -> RawCopy()
This commit is contained in:
committed by
Jakob Borg
parent
a1a91d5ef4
commit
f60b424d70
@@ -43,7 +43,7 @@ func (validationError) String() string {
|
||||
|
||||
func TestReplaceCommit(t *testing.T) {
|
||||
w := Wrap("/dev/null", Configuration{Version: 0})
|
||||
if w.Raw().Version != 0 {
|
||||
if w.RawCopy().Version != 0 {
|
||||
t.Fatal("Config incorrect")
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func TestReplaceCommit(t *testing.T) {
|
||||
if w.RequiresRestart() {
|
||||
t.Fatal("Should not require restart")
|
||||
}
|
||||
if w.Raw().Version != CurrentVersion {
|
||||
if w.RawCopy().Version != CurrentVersion {
|
||||
t.Fatal("Config should have changed")
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ func TestReplaceCommit(t *testing.T) {
|
||||
if !w.RequiresRestart() {
|
||||
t.Fatal("Should require restart")
|
||||
}
|
||||
if w.Raw().Version != CurrentVersion {
|
||||
if w.RawCopy().Version != CurrentVersion {
|
||||
t.Fatal("Config should have changed")
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ func TestReplaceCommit(t *testing.T) {
|
||||
if !w.RequiresRestart() {
|
||||
t.Fatal("Should still require restart")
|
||||
}
|
||||
if w.Raw().Version != CurrentVersion {
|
||||
if w.RawCopy().Version != CurrentVersion {
|
||||
t.Fatal("Config should not have changed")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,7 +456,7 @@ func TestNewSaveLoad(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if diff, equal := messagediff.PrettyDiff(cfg.Raw(), cfg2.Raw()); !equal {
|
||||
if diff, equal := messagediff.PrettyDiff(cfg.RawCopy(), cfg2.RawCopy()); !equal {
|
||||
t.Errorf("Configs are not equal. Diff:\n%s", diff)
|
||||
}
|
||||
|
||||
@@ -482,7 +482,7 @@ func TestCopy(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg := wrapper.Raw()
|
||||
cfg := wrapper.RawCopy()
|
||||
|
||||
bsOrig, err := json.MarshalIndent(cfg, "", " ")
|
||||
if err != nil {
|
||||
@@ -548,7 +548,7 @@ func TestPullOrder(t *testing.T) {
|
||||
// Serialize and deserialize again to verify it survives the transformation
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
cfg := wrapper.Raw()
|
||||
cfg := wrapper.RawCopy()
|
||||
cfg.WriteXML(buf)
|
||||
|
||||
t.Logf("%s", buf.Bytes())
|
||||
@@ -611,7 +611,7 @@ func TestDuplicateDevices(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if l := len(wrapper.Raw().Devices); l != 3 {
|
||||
if l := len(wrapper.RawCopy().Devices); l != 3 {
|
||||
t.Errorf("Incorrect number of devices, %d != 3", l)
|
||||
}
|
||||
|
||||
@@ -755,7 +755,7 @@ func TestSharesRemovedOnDeviceRemoval(t *testing.T) {
|
||||
t.Errorf("Failed: %s", err)
|
||||
}
|
||||
|
||||
raw := wrapper.Raw()
|
||||
raw := wrapper.RawCopy()
|
||||
raw.Devices = raw.Devices[:len(raw.Devices)-1]
|
||||
|
||||
if len(raw.Folders[0].Devices) <= len(raw.Devices) {
|
||||
@@ -767,7 +767,7 @@ func TestSharesRemovedOnDeviceRemoval(t *testing.T) {
|
||||
t.Errorf("Failed: %s", err)
|
||||
}
|
||||
|
||||
raw = wrapper.Raw()
|
||||
raw = wrapper.RawCopy()
|
||||
if len(raw.Folders[0].Devices) > len(raw.Devices) {
|
||||
t.Error("Unexpected extra device")
|
||||
}
|
||||
|
||||
@@ -120,9 +120,11 @@ func (w *Wrapper) Unsubscribe(c Committer) {
|
||||
w.mut.Unlock()
|
||||
}
|
||||
|
||||
// Raw returns the currently wrapped Configuration object.
|
||||
func (w *Wrapper) Raw() Configuration {
|
||||
return w.cfg
|
||||
// RawCopy returns a copy of the currently wrapped Configuration object.
|
||||
func (w *Wrapper) RawCopy() Configuration {
|
||||
w.mut.Lock()
|
||||
defer w.mut.Unlock()
|
||||
return w.cfg.Copy()
|
||||
}
|
||||
|
||||
// Replace swaps the current configuration object for the given one.
|
||||
|
||||
@@ -112,7 +112,7 @@ func NewService(cfg *config.Wrapper, myID protocol.DeviceID, mdl Model, tlsCfg *
|
||||
service.Add(serviceFunc(service.connect))
|
||||
service.Add(serviceFunc(service.handle))
|
||||
|
||||
raw := cfg.Raw()
|
||||
raw := cfg.RawCopy()
|
||||
// Actually starts the listeners and NAT service
|
||||
service.CommitConfiguration(raw, raw)
|
||||
|
||||
@@ -276,7 +276,7 @@ func (s *Service) connect() {
|
||||
var sleep time.Duration
|
||||
|
||||
for {
|
||||
cfg := s.cfg.Raw()
|
||||
cfg := s.cfg.RawCopy()
|
||||
|
||||
bestDialerPrio := 1<<31 - 1 // worse prio won't build on 32 bit
|
||||
for _, df := range dialers {
|
||||
|
||||
@@ -970,7 +970,7 @@ func (m *Model) handleDeintroductions(introducerCfg config.DeviceConfiguration,
|
||||
|
||||
// Check if we should remove some devices, if the introducer no longer shares any folder with them.
|
||||
// Yet do not remove if we share other folders that haven't been introduced by the introducer.
|
||||
raw := m.cfg.Raw()
|
||||
raw := m.cfg.RawCopy()
|
||||
deviceChanged := false
|
||||
for i := 0; i < len(raw.Devices); i++ {
|
||||
if raw.Devices[i].IntroducedBy == introducerCfg.DeviceID {
|
||||
|
||||
@@ -42,7 +42,7 @@ func NewProgressEmitter(cfg *config.Wrapper) *ProgressEmitter {
|
||||
mut: sync.NewMutex(),
|
||||
}
|
||||
|
||||
t.CommitConfiguration(config.Configuration{}, cfg.Raw())
|
||||
t.CommitConfiguration(config.Configuration{}, cfg.RawCopy())
|
||||
cfg.Subscribe(t)
|
||||
|
||||
return t
|
||||
|
||||
Reference in New Issue
Block a user