mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-26 03:25:35 +00:00
ipn/store: [TestNewStore] do not use an empty file
Otherwise it would log warnings about an empty file. ``` stores.go:138: store.NewFileStore("/tmp/3777352782"): file empty; treating it like a missing file [warning] ``` Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
parent
497324ddf6
commit
518f6cee63
@ -10,7 +10,6 @@
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -125,7 +124,7 @@ func (s *FileStore) Path() string { return s.path }
|
|||||||
func (s *FileStore) String() string { return fmt.Sprintf("FileStore(%q)", s.path) }
|
func (s *FileStore) String() string { return fmt.Sprintf("FileStore(%q)", s.path) }
|
||||||
|
|
||||||
// NewFileStore returns a new file store that persists to path.
|
// NewFileStore returns a new file store that persists to path.
|
||||||
func NewFileStore(_ logger.Logf, path string) (ipn.StateStore, error) {
|
func NewFileStore(logf logger.Logf, path string) (ipn.StateStore, error) {
|
||||||
// We unconditionally call this to ensure that our perms are correct
|
// We unconditionally call this to ensure that our perms are correct
|
||||||
if err := paths.MkStateDir(filepath.Dir(path)); err != nil {
|
if err := paths.MkStateDir(filepath.Dir(path)); err != nil {
|
||||||
return nil, fmt.Errorf("creating state directory: %w", err)
|
return nil, fmt.Errorf("creating state directory: %w", err)
|
||||||
@ -136,7 +135,7 @@ func NewFileStore(_ logger.Logf, path string) (ipn.StateStore, error) {
|
|||||||
// Treat an empty file as a missing file.
|
// Treat an empty file as a missing file.
|
||||||
// (https://github.com/tailscale/tailscale/issues/895#issuecomment-723255589)
|
// (https://github.com/tailscale/tailscale/issues/895#issuecomment-723255589)
|
||||||
if err == nil && len(bs) == 0 {
|
if err == nil && len(bs) == 0 {
|
||||||
log.Printf("ipn.NewFileStore(%q): file empty; treating it like a missing file [warning]", path)
|
logf("store.NewFileStore(%q): file empty; treating it like a missing file [warning]", path)
|
||||||
err = os.ErrNotExist
|
err = os.ErrNotExist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
package store
|
package store
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -63,18 +62,8 @@ type store2 struct {
|
|||||||
} else if _, ok := s.(*store2); !ok {
|
} else if _, ok := s.(*store2); !ok {
|
||||||
t.Fatalf("%q: got: %T, want: %T", path, s, new(store2))
|
t.Fatalf("%q: got: %T, want: %T", path, s, new(store2))
|
||||||
}
|
}
|
||||||
f, err := os.CreateTemp("", "")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if err := f.Close(); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
t.Cleanup(func() {
|
|
||||||
os.Remove(f.Name())
|
|
||||||
})
|
|
||||||
|
|
||||||
path = f.Name()
|
path = filepath.Join(t.TempDir(), "state")
|
||||||
if s, err := New(t.Logf, path); err != nil {
|
if s, err := New(t.Logf, path); err != nil {
|
||||||
t.Fatalf("%q: %v", path, err)
|
t.Fatalf("%q: %v", path, err)
|
||||||
} else if _, ok := s.(*FileStore); !ok {
|
} else if _, ok := s.(*FileStore); !ok {
|
||||||
|
Loading…
Reference in New Issue
Block a user