diff options
| author | Brad Fitzpatrick <bradfitz@tailscale.com> | 2020-11-06 12:56:24 -0800 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@tailscale.com> | 2020-11-06 12:56:48 -0800 |
| commit | e369e8b92135b76ca6c2bdee31f083e1f634e8c9 (patch) | |
| tree | d21f69b2a7dc9912c05a4a844c9e15163ac9c8d7 | |
| parent | 119101962c9e2867b97809dd6252479a1fffea1a (diff) | |
| download | tailscale-bradfitz/ipn_empty.tar.xz tailscale-bradfitz/ipn_empty.zip | |
ipn: treat zero-length file state store file as missingbradfitz/ipn_empty
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
| -rw-r--r-- | ipn/store.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/ipn/store.go b/ipn/store.go index d586f5729..117c68ca7 100644 --- a/ipn/store.go +++ b/ipn/store.go @@ -10,6 +10,7 @@ import ( "errors" "fmt" "io/ioutil" + "log" "os" "path/filepath" "sync" @@ -100,6 +101,14 @@ func (s *FileStore) String() string { return fmt.Sprintf("FileStore(%q)", s.path // NewFileStore returns a new file store that persists to path. func NewFileStore(path string) (*FileStore, error) { bs, err := ioutil.ReadFile(path) + + // Treat an empty file as a missing file. + // (https://github.com/tailscale/tailscale/issues/895#issuecomment-723255589) + if err == nil && len(bs) == 0 { + log.Printf("ipn.NewFileStore(%q): file empty; treating it like a missing file [warning]", path) + err = os.ErrNotExist + } + if err != nil { if os.IsNotExist(err) { // Write out an initial file, to verify that we can write |
