ipn/ipnlocal: simplify loadStateLocked control flow a bit, restore logging

The common Linux start-up path (fallback file defined but not
existing) was missing the log print of initializing Prefs. The code
was too twisty. Simplify a bit.

Updates #1573

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2021-04-02 07:56:07 -07:00
parent a39d2403bc
commit d50406f185
1 changed files with 10 additions and 7 deletions

View File

@ -1061,17 +1061,20 @@ func (b *LocalBackend) loadStateLocked(key ipn.StateKey, prefs *ipn.Prefs, legac
bs, err := b.store.ReadState(key)
switch {
case errors.Is(err, ipn.ErrStateNotExist):
loaded := false
if legacyPath != "" {
b.prefs, err = ipn.LoadPrefs(legacyPath)
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
switch {
case errors.Is(err, os.ErrNotExist):
// Quiet. Normal case.
case err != nil:
b.logf("failed to load legacy prefs: %v", err)
}
b.prefs = ipn.NewPrefs()
} else {
default:
loaded = true
b.logf("imported prefs from relaynode for %q: %v", key, b.prefs.Pretty())
}
} else {
}
if !loaded {
b.prefs = ipn.NewPrefs()
b.logf("created empty state for %q: %s", key, b.prefs.Pretty())
}