mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-11 15:17:18 +00:00
all: rename deep "Copy" methods to conventional Go name "Clone"
This commit is contained in:
@@ -58,7 +58,7 @@ func (b *FakeBackend) SetPrefs(new *Prefs) {
|
||||
panic("FakeBackend.SetPrefs got nil prefs")
|
||||
}
|
||||
|
||||
b.notify(Notify{Prefs: new.Copy()})
|
||||
b.notify(Notify{Prefs: new.Clone()})
|
||||
if new.WantRunning && !b.live {
|
||||
b.newState(Starting)
|
||||
b.newState(Running)
|
||||
|
@@ -47,7 +47,7 @@ func (h *Handle) Start(opts Options) error {
|
||||
h.engineStatusCache = EngineStatus{}
|
||||
h.stateCache = NoState
|
||||
if opts.Prefs != nil {
|
||||
h.prefsCache = opts.Prefs.Copy()
|
||||
h.prefsCache = opts.Prefs.Clone()
|
||||
}
|
||||
xopts := opts
|
||||
xopts.Notify = h.notify
|
||||
@@ -69,7 +69,7 @@ func (h *Handle) notify(n Notify) {
|
||||
h.stateCache = *n.State
|
||||
}
|
||||
if n.Prefs != nil {
|
||||
h.prefsCache = n.Prefs.Copy()
|
||||
h.prefsCache = n.Prefs.Clone()
|
||||
}
|
||||
if n.NetMap != nil {
|
||||
h.netmapCache = n.NetMap
|
||||
@@ -89,14 +89,14 @@ func (h *Handle) Prefs() *Prefs {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
|
||||
return h.prefsCache.Copy()
|
||||
return h.prefsCache.Clone()
|
||||
}
|
||||
|
||||
func (h *Handle) UpdatePrefs(updateFn func(p *Prefs)) {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
|
||||
new := h.prefsCache.Copy()
|
||||
new := h.prefsCache.Clone()
|
||||
updateFn(new)
|
||||
h.prefsCache = new
|
||||
h.b.SetPrefs(new)
|
||||
|
@@ -212,7 +212,7 @@ func (b *LocalBackend) Start(opts Options) error {
|
||||
b.logf("Failed to save new controlclient state: %v", err)
|
||||
}
|
||||
}
|
||||
b.send(Notify{Prefs: b.prefs.Copy()})
|
||||
b.send(Notify{Prefs: b.prefs.Clone()})
|
||||
}
|
||||
if newSt.NetMap != nil {
|
||||
if b.netMapCache != nil && b.cmpDiff != nil {
|
||||
@@ -282,7 +282,7 @@ func (b *LocalBackend) Start(opts Options) error {
|
||||
blid := b.backendLogID
|
||||
b.logf("Backend: logs: be:%v fe:%v\n", blid, opts.FrontendLogID)
|
||||
b.send(Notify{BackendLogID: &blid})
|
||||
b.send(Notify{Prefs: b.prefs.Copy()})
|
||||
b.send(Notify{Prefs: b.prefs.Clone()})
|
||||
|
||||
cli.Login(nil, controlclient.LoginDefault)
|
||||
return nil
|
||||
@@ -383,7 +383,7 @@ func (b *LocalBackend) loadStateLocked(key StateKey, prefs *Prefs, legacyPath st
|
||||
if key == "" {
|
||||
// Frontend fully owns the state, we just need to obey it.
|
||||
b.logf("Using frontend prefs")
|
||||
b.prefs = prefs.Copy()
|
||||
b.prefs = prefs.Clone()
|
||||
b.stateKey = ""
|
||||
return nil
|
||||
}
|
||||
@@ -535,7 +535,7 @@ func (b *LocalBackend) SetPrefs(new *Prefs) {
|
||||
}
|
||||
}
|
||||
oldHi := b.hiCache
|
||||
newHi := oldHi.Copy()
|
||||
newHi := oldHi.Clone()
|
||||
newHi.RoutableIPs = append([]wgcfg.CIDR(nil), b.prefs.AdvertiseRoutes...)
|
||||
b.hiCache = newHi
|
||||
cli := b.c
|
||||
|
@@ -156,8 +156,9 @@ func PrefsFromBytes(b []byte, enforceDefaults bool) (*Prefs, error) {
|
||||
return p, err
|
||||
}
|
||||
|
||||
// Copy returns a deep copy of p.
|
||||
func (p *Prefs) Copy() *Prefs {
|
||||
// Clone returns a deep copy of p.
|
||||
func (p *Prefs) Clone() *Prefs {
|
||||
// TODO: write a faster/non-Fatal-y Clone implementation?
|
||||
p2, err := PrefsFromBytes(p.ToBytes(), false)
|
||||
if err != nil {
|
||||
log.Fatalf("Prefs was uncopyable: %v\n", err)
|
||||
|
@@ -195,7 +195,7 @@ func checkPrefs(t *testing.T, p Prefs) {
|
||||
if !p.Equals(&p) {
|
||||
t.Fatalf("p != p\n")
|
||||
}
|
||||
p2 = p.Copy()
|
||||
p2 = p.Clone()
|
||||
p2.RouteAll = true
|
||||
if p.Equals(p2) {
|
||||
t.Fatalf("p == p2\n")
|
||||
@@ -213,7 +213,7 @@ func checkPrefs(t *testing.T, p Prefs) {
|
||||
if !p2.Equals(p2b) {
|
||||
t.Fatalf("p2 != p2b\n%#v\n%#v\n", p2, p2b)
|
||||
}
|
||||
p2c = p2.Copy()
|
||||
p2c = p2.Clone()
|
||||
if !p2b.Equals(p2c) {
|
||||
t.Fatalf("p2b != p2c\n")
|
||||
}
|
||||
|
Reference in New Issue
Block a user