*: use filepath.Join for files

This commit is contained in:
Anthony Romano 2017-03-15 19:31:10 -07:00 committed by Gyu-Ho Lee
parent b478387a59
commit 8c3c1b4a9c
19 changed files with 74 additions and 73 deletions

View File

@ -19,7 +19,7 @@ import (
"fmt" "fmt"
"net" "net"
"net/http" "net/http"
"path" "path/filepath"
"github.com/coreos/etcd/etcdserver" "github.com/coreos/etcd/etcdserver"
"github.com/coreos/etcd/etcdserver/api/v2http" "github.com/coreos/etcd/etcdserver/api/v2http"
@ -166,7 +166,7 @@ func startPeerListeners(cfg *Config) (plns []net.Listener, err error) {
for i, u := range cfg.LPUrls { for i, u := range cfg.LPUrls {
phosts[i] = u.Host phosts[i] = u.Host
} }
cfg.PeerTLSInfo, err = transport.SelfCert(path.Join(cfg.Dir, "fixtures/peer"), phosts) cfg.PeerTLSInfo, err = transport.SelfCert(filepath.Join(cfg.Dir, "fixtures", "peer"), phosts)
if err != nil { if err != nil {
plog.Fatalf("could not get certs (%v)", err) plog.Fatalf("could not get certs (%v)", err)
} }
@ -221,7 +221,7 @@ func startClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err error) {
for i, u := range cfg.LCUrls { for i, u := range cfg.LCUrls {
chosts[i] = u.Host chosts[i] = u.Host
} }
cfg.ClientTLSInfo, err = transport.SelfCert(path.Join(cfg.Dir, "fixtures/client"), chosts) cfg.ClientTLSInfo, err = transport.SelfCert(filepath.Join(cfg.Dir, "fixtures", "client"), chosts)
if err != nil { if err != nil {
plog.Fatalf("could not get certs (%v)", err) plog.Fatalf("could not get certs (%v)", err)
} }

View File

@ -15,7 +15,7 @@
package embed package embed
import ( import (
"path" "path/filepath"
"github.com/coreos/etcd/wal" "github.com/coreos/etcd/wal"
) )
@ -23,7 +23,7 @@ import (
func isMemberInitialized(cfg *Config) bool { func isMemberInitialized(cfg *Config) bool {
waldir := cfg.WalDir waldir := cfg.WalDir
if waldir == "" { if waldir == "" {
waldir = path.Join(cfg.Dir, "member", "wal") waldir = filepath.Join(cfg.Dir, "member", "wal")
} }
return wal.Exist(waldir) return wal.Exist(waldir)

View File

@ -17,7 +17,7 @@ package command
import ( import (
"fmt" "fmt"
"log" "log"
"path" "path/filepath"
"time" "time"
"github.com/coreos/etcd/etcdserver/etcdserverpb" "github.com/coreos/etcd/etcdserver/etcdserverpb"
@ -50,19 +50,19 @@ func handleBackup(c *cli.Context) error {
var srcWAL string var srcWAL string
var destWAL string var destWAL string
srcSnap := path.Join(c.String("data-dir"), "member", "snap") srcSnap := filepath.Join(c.String("data-dir"), "member", "snap")
destSnap := path.Join(c.String("backup-dir"), "member", "snap") destSnap := filepath.Join(c.String("backup-dir"), "member", "snap")
if c.String("wal-dir") != "" { if c.String("wal-dir") != "" {
srcWAL = c.String("wal-dir") srcWAL = c.String("wal-dir")
} else { } else {
srcWAL = path.Join(c.String("data-dir"), "member", "wal") srcWAL = filepath.Join(c.String("data-dir"), "member", "wal")
} }
if c.String("backup-wal-dir") != "" { if c.String("backup-wal-dir") != "" {
destWAL = c.String("backup-wal-dir") destWAL = c.String("backup-wal-dir")
} else { } else {
destWAL = path.Join(c.String("backup-dir"), "member", "wal") destWAL = filepath.Join(c.String("backup-dir"), "member", "wal")
} }
if err := fileutil.CreateDirAll(destSnap); err != nil { if err := fileutil.CreateDirAll(destSnap); err != nil {

View File

@ -21,7 +21,7 @@ import (
"io" "io"
"os" "os"
"os/exec" "os/exec"
"path" "path/filepath"
"time" "time"
"github.com/coreos/etcd/client" "github.com/coreos/etcd/client"
@ -103,7 +103,7 @@ func prepareBackend() backend.Backend {
var be backend.Backend var be backend.Backend
bch := make(chan struct{}) bch := make(chan struct{})
dbpath := path.Join(migrateDatadir, "member", "snap", "db") dbpath := filepath.Join(migrateDatadir, "member", "snap", "db")
go func() { go func() {
defer close(bch) defer close(bch)
be = backend.New(dbpath, time.Second, 10000) be = backend.New(dbpath, time.Second, 10000)
@ -130,9 +130,9 @@ func rebuildStoreV2() (store.Store, uint64) {
waldir := migrateWALdir waldir := migrateWALdir
if len(waldir) == 0 { if len(waldir) == 0 {
waldir = path.Join(migrateDatadir, "member", "wal") waldir = filepath.Join(migrateDatadir, "member", "wal")
} }
snapdir := path.Join(migrateDatadir, "member", "snap") snapdir := filepath.Join(migrateDatadir, "member", "snap")
ss := snap.New(snapdir) ss := snap.New(snapdir)
snapshot, err := ss.Load() snapshot, err := ss.Load()

View File

@ -23,7 +23,7 @@ import (
"io" "io"
"math" "math"
"os" "os"
"path" "path/filepath"
"reflect" "reflect"
"strings" "strings"
@ -186,8 +186,8 @@ func snapshotRestoreCommandFunc(cmd *cobra.Command, args []string) {
basedir = restoreName + ".etcd" basedir = restoreName + ".etcd"
} }
waldir := path.Join(basedir, "member", "wal") waldir := filepath.Join(basedir, "member", "wal")
snapdir := path.Join(basedir, "member", "snap") snapdir := filepath.Join(basedir, "member", "snap")
if _, err := os.Stat(basedir); err == nil { if _, err := os.Stat(basedir); err == nil {
ExitWithError(ExitInvalidInput, fmt.Errorf("data-dir %q exists", basedir)) ExitWithError(ExitInvalidInput, fmt.Errorf("data-dir %q exists", basedir))
@ -325,7 +325,7 @@ func makeDB(snapdir, dbfile string, commit int) {
ExitWithError(ExitIO, err) ExitWithError(ExitIO, err)
} }
dbpath := path.Join(snapdir, "db") dbpath := filepath.Join(snapdir, "db")
db, dberr := os.OpenFile(dbpath, os.O_RDWR|os.O_CREATE, 0600) db, dberr := os.OpenFile(dbpath, os.O_RDWR|os.O_CREATE, 0600)
if dberr != nil { if dberr != nil {
ExitWithError(ExitIO, dberr) ExitWithError(ExitIO, dberr)

View File

@ -22,7 +22,7 @@ import (
"net" "net"
"net/http" "net/http"
"os" "os"
"path" "path/filepath"
"reflect" "reflect"
"runtime" "runtime"
"strings" "strings"
@ -211,14 +211,14 @@ func startProxy(cfg *config) error {
return err return err
} }
cfg.Dir = path.Join(cfg.Dir, "proxy") cfg.Dir = filepath.Join(cfg.Dir, "proxy")
err = os.MkdirAll(cfg.Dir, fileutil.PrivateDirMode) err = os.MkdirAll(cfg.Dir, fileutil.PrivateDirMode)
if err != nil { if err != nil {
return err return err
} }
var peerURLs []string var peerURLs []string
clusterfile := path.Join(cfg.Dir, "cluster") clusterfile := filepath.Join(cfg.Dir, "cluster")
b, err := ioutil.ReadFile(clusterfile) b, err := ioutil.ReadFile(clusterfile)
switch { switch {

View File

@ -16,7 +16,7 @@ package etcdserver
import ( import (
"fmt" "fmt"
"path" "path/filepath"
"sort" "sort"
"strings" "strings"
"time" "time"
@ -118,16 +118,16 @@ func (c *ServerConfig) advertiseMatchesCluster() error {
return nil return nil
} }
func (c *ServerConfig) MemberDir() string { return path.Join(c.DataDir, "member") } func (c *ServerConfig) MemberDir() string { return filepath.Join(c.DataDir, "member") }
func (c *ServerConfig) WALDir() string { func (c *ServerConfig) WALDir() string {
if c.DedicatedWALDir != "" { if c.DedicatedWALDir != "" {
return c.DedicatedWALDir return c.DedicatedWALDir
} }
return path.Join(c.MemberDir(), "wal") return filepath.Join(c.MemberDir(), "wal")
} }
func (c *ServerConfig) SnapDir() string { return path.Join(c.MemberDir(), "snap") } func (c *ServerConfig) SnapDir() string { return filepath.Join(c.MemberDir(), "snap") }
func (c *ServerConfig) ShouldDiscover() bool { return c.DiscoveryURL != "" } func (c *ServerConfig) ShouldDiscover() bool { return c.DiscoveryURL != "" }

View File

@ -23,6 +23,7 @@ import (
"net/http" "net/http"
"os" "os"
"path" "path"
"path/filepath"
"regexp" "regexp"
"sync" "sync"
"sync/atomic" "sync/atomic"
@ -263,7 +264,7 @@ func NewServer(cfg *ServerConfig) (srv *EtcdServer, err error) {
} }
ss := snap.New(cfg.SnapDir()) ss := snap.New(cfg.SnapDir())
bepath := path.Join(cfg.SnapDir(), databaseFilename) bepath := filepath.Join(cfg.SnapDir(), databaseFilename)
beExist := fileutil.Exist(bepath) beExist := fileutil.Exist(bepath)
var be backend.Backend var be backend.Backend
@ -791,7 +792,7 @@ func (s *EtcdServer) applySnapshot(ep *etcdProgress, apply *apply) {
plog.Panicf("get database snapshot file path error: %v", err) plog.Panicf("get database snapshot file path error: %v", err)
} }
fn := path.Join(s.Cfg.SnapDir(), databaseFilename) fn := filepath.Join(s.Cfg.SnapDir(), databaseFilename)
if err := os.Rename(snapfn, fn); err != nil { if err := os.Rename(snapfn, fn); err != nil {
plog.Panicf("rename snapshot file error: %v", err) plog.Panicf("rename snapshot file error: %v", err)
} }

View File

@ -18,7 +18,7 @@ import (
"fmt" "fmt"
"net/url" "net/url"
"os" "os"
"path" "path/filepath"
"strings" "strings"
"testing" "testing"
@ -58,7 +58,7 @@ func TestEmbedEtcd(t *testing.T) {
setupEmbedCfg(&tests[5].cfg, []url.URL{urls[4]}, []url.URL{urls[5], urls[6]}) setupEmbedCfg(&tests[5].cfg, []url.URL{urls[4]}, []url.URL{urls[5], urls[6]})
setupEmbedCfg(&tests[6].cfg, []url.URL{urls[7], urls[8]}, []url.URL{urls[9]}) setupEmbedCfg(&tests[6].cfg, []url.URL{urls[7], urls[8]}, []url.URL{urls[9]})
dir := path.Join(os.TempDir(), fmt.Sprintf("embed-etcd")) dir := filepath.Join(os.TempDir(), fmt.Sprintf("embed-etcd"))
os.RemoveAll(dir) os.RemoveAll(dir)
defer os.RemoveAll(dir) defer os.RemoveAll(dir)

View File

@ -18,7 +18,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path/filepath"
"reflect" "reflect"
"sort" "sort"
"sync" "sync"
@ -400,5 +400,5 @@ func NewTestBackend(t *testing.T) (string, backend.Backend) {
t.Fatalf("failed to create tmpdir (%v)", err) t.Fatalf("failed to create tmpdir (%v)", err)
} }
return tmpPath, backend.New(path.Join(tmpPath, "be"), time.Second, 10000) return tmpPath, backend.New(filepath.Join(tmpPath, "be"), time.Second, 10000)
} }

View File

@ -20,7 +20,7 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path/filepath"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
@ -337,7 +337,7 @@ func NewTmpBackend(batchInterval time.Duration, batchLimit int) (*backend, strin
if err != nil { if err != nil {
plog.Fatal(err) plog.Fatal(err)
} }
tmpPath := path.Join(dir, "database") tmpPath := filepath.Join(dir, "database")
return newBackend(tmpPath, batchInterval, batchLimit), tmpPath return newBackend(tmpPath, batchInterval, batchLimit), tmpPath
} }

View File

@ -19,7 +19,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path/filepath"
"sort" "sort"
"github.com/coreos/pkg/capnslog" "github.com/coreos/pkg/capnslog"
@ -39,7 +39,7 @@ var (
// IsDirWriteable checks if dir is writable by writing and removing a file // IsDirWriteable checks if dir is writable by writing and removing a file
// to dir. It returns nil if dir is writable. // to dir. It returns nil if dir is writable.
func IsDirWriteable(dir string) error { func IsDirWriteable(dir string) error {
f := path.Join(dir, ".touch") f := filepath.Join(dir, ".touch")
if err := ioutil.WriteFile(f, []byte(""), PrivateFileMode); err != nil { if err := ioutil.WriteFile(f, []byte(""), PrivateFileMode); err != nil {
return err return err
} }

View File

@ -16,7 +16,7 @@ package fileutil
import ( import (
"os" "os"
"path" "path/filepath"
"sort" "sort"
"strings" "strings"
"time" "time"
@ -45,7 +45,7 @@ func purgeFile(dirname string, suffix string, max uint, interval time.Duration,
sort.Strings(newfnames) sort.Strings(newfnames)
fnames = newfnames fnames = newfnames
for len(newfnames) > int(max) { for len(newfnames) > int(max) {
f := path.Join(dirname, newfnames[0]) f := filepath.Join(dirname, newfnames[0])
l, err := TryLockFile(f, os.O_WRONLY, PrivateFileMode) l, err := TryLockFile(f, os.O_WRONLY, PrivateFileMode)
if err != nil { if err != nil {
break break

View File

@ -18,7 +18,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path/filepath"
"reflect" "reflect"
"testing" "testing"
"time" "time"
@ -33,7 +33,7 @@ func TestPurgeFile(t *testing.T) {
// minimal file set // minimal file set
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
f, ferr := os.Create(path.Join(dir, fmt.Sprintf("%d.test", i))) f, ferr := os.Create(filepath.Join(dir, fmt.Sprintf("%d.test", i)))
if ferr != nil { if ferr != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -53,7 +53,7 @@ func TestPurgeFile(t *testing.T) {
// rest of the files // rest of the files
for i := 4; i < 10; i++ { for i := 4; i < 10; i++ {
go func(n int) { go func(n int) {
f, ferr := os.Create(path.Join(dir, fmt.Sprintf("%d.test", n))) f, ferr := os.Create(filepath.Join(dir, fmt.Sprintf("%d.test", n)))
if ferr != nil { if ferr != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -99,7 +99,7 @@ func TestPurgeFileHoldingLockFile(t *testing.T) {
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
var f *os.File var f *os.File
f, err = os.Create(path.Join(dir, fmt.Sprintf("%d.test", i))) f, err = os.Create(filepath.Join(dir, fmt.Sprintf("%d.test", i)))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -107,7 +107,7 @@ func TestPurgeFileHoldingLockFile(t *testing.T) {
} }
// create a purge barrier at 5 // create a purge barrier at 5
p := path.Join(dir, fmt.Sprintf("%d.test", 5)) p := filepath.Join(dir, fmt.Sprintf("%d.test", 5))
l, err := LockFile(p, os.O_WRONLY, PrivateFileMode) l, err := LockFile(p, os.O_WRONLY, PrivateFileMode)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@ -27,7 +27,7 @@ import (
"math/big" "math/big"
"net" "net"
"os" "os"
"path" "path/filepath"
"strings" "strings"
"time" "time"
@ -91,8 +91,8 @@ func SelfCert(dirpath string, hosts []string) (info TLSInfo, err error) {
return return
} }
certPath := path.Join(dirpath, "cert.pem") certPath := filepath.Join(dirpath, "cert.pem")
keyPath := path.Join(dirpath, "key.pem") keyPath := filepath.Join(dirpath, "key.pem")
_, errcert := os.Stat(certPath) _, errcert := os.Stat(certPath)
_, errkey := os.Stat(keyPath) _, errkey := os.Stat(keyPath)
if errcert == nil && errkey == nil { if errcert == nil && errkey == nil {

View File

@ -19,7 +19,7 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path/filepath"
"github.com/coreos/etcd/pkg/fileutil" "github.com/coreos/etcd/pkg/fileutil"
) )
@ -41,7 +41,7 @@ func (s *Snapshotter) SaveDBFrom(r io.Reader, id uint64) (int64, error) {
os.Remove(f.Name()) os.Remove(f.Name())
return n, err return n, err
} }
fn := path.Join(s.dir, fmt.Sprintf("%016x.snap.db", id)) fn := filepath.Join(s.dir, fmt.Sprintf("%016x.snap.db", id))
if fileutil.Exist(fn) { if fileutil.Exist(fn) {
os.Remove(f.Name()) os.Remove(f.Name())
return n, nil return n, nil
@ -67,7 +67,7 @@ func (s *Snapshotter) DBFilePath(id uint64) (string, error) {
wfn := fmt.Sprintf("%016x.snap.db", id) wfn := fmt.Sprintf("%016x.snap.db", id)
for _, fn := range fns { for _, fn := range fns {
if fn == wfn { if fn == wfn {
return path.Join(s.dir, fn), nil return filepath.Join(s.dir, fn), nil
} }
} }
return "", fmt.Errorf("snap: snapshot file doesn't exist") return "", fmt.Errorf("snap: snapshot file doesn't exist")

View File

@ -21,7 +21,7 @@ import (
"hash/crc32" "hash/crc32"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path/filepath"
"sort" "sort"
"strings" "strings"
"time" "time"
@ -84,13 +84,13 @@ func (s *Snapshotter) save(snapshot *raftpb.Snapshot) error {
marshallingDurations.Observe(float64(time.Since(start)) / float64(time.Second)) marshallingDurations.Observe(float64(time.Since(start)) / float64(time.Second))
} }
err = pioutil.WriteAndSyncFile(path.Join(s.dir, fname), d, 0666) err = pioutil.WriteAndSyncFile(filepath.Join(s.dir, fname), d, 0666)
if err == nil { if err == nil {
saveDurations.Observe(float64(time.Since(start)) / float64(time.Second)) saveDurations.Observe(float64(time.Since(start)) / float64(time.Second))
} else { } else {
err1 := os.Remove(path.Join(s.dir, fname)) err1 := os.Remove(filepath.Join(s.dir, fname))
if err1 != nil { if err1 != nil {
plog.Errorf("failed to remove broken snapshot file %s", path.Join(s.dir, fname)) plog.Errorf("failed to remove broken snapshot file %s", filepath.Join(s.dir, fname))
} }
} }
return err return err
@ -114,7 +114,7 @@ func (s *Snapshotter) Load() (*raftpb.Snapshot, error) {
} }
func loadSnap(dir, name string) (*raftpb.Snapshot, error) { func loadSnap(dir, name string) (*raftpb.Snapshot, error) {
fpath := path.Join(dir, name) fpath := filepath.Join(dir, name)
snap, err := Read(fpath) snap, err := Read(fpath)
if err != nil { if err != nil {
renameBroken(fpath) renameBroken(fpath)

View File

@ -19,7 +19,7 @@ import (
"hash/crc32" "hash/crc32"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path/filepath"
"reflect" "reflect"
"testing" "testing"
@ -38,7 +38,7 @@ var testSnap = &raftpb.Snapshot{
} }
func TestSaveAndLoad(t *testing.T) { func TestSaveAndLoad(t *testing.T) {
dir := path.Join(os.TempDir(), "snapshot") dir := filepath.Join(os.TempDir(), "snapshot")
err := os.Mkdir(dir, 0700) err := os.Mkdir(dir, 0700)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -60,7 +60,7 @@ func TestSaveAndLoad(t *testing.T) {
} }
func TestBadCRC(t *testing.T) { func TestBadCRC(t *testing.T) {
dir := path.Join(os.TempDir(), "snapshot") dir := filepath.Join(os.TempDir(), "snapshot")
err := os.Mkdir(dir, 0700) err := os.Mkdir(dir, 0700)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -76,14 +76,14 @@ func TestBadCRC(t *testing.T) {
// fake a crc mismatch // fake a crc mismatch
crcTable = crc32.MakeTable(crc32.Koopman) crcTable = crc32.MakeTable(crc32.Koopman)
_, err = Read(path.Join(dir, fmt.Sprintf("%016x-%016x.snap", 1, 1))) _, err = Read(filepath.Join(dir, fmt.Sprintf("%016x-%016x.snap", 1, 1)))
if err == nil || err != ErrCRCMismatch { if err == nil || err != ErrCRCMismatch {
t.Errorf("err = %v, want %v", err, ErrCRCMismatch) t.Errorf("err = %v, want %v", err, ErrCRCMismatch)
} }
} }
func TestFailback(t *testing.T) { func TestFailback(t *testing.T) {
dir := path.Join(os.TempDir(), "snapshot") dir := filepath.Join(os.TempDir(), "snapshot")
err := os.Mkdir(dir, 0700) err := os.Mkdir(dir, 0700)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -91,7 +91,7 @@ func TestFailback(t *testing.T) {
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
large := fmt.Sprintf("%016x-%016x-%016x.snap", 0xFFFF, 0xFFFF, 0xFFFF) large := fmt.Sprintf("%016x-%016x-%016x.snap", 0xFFFF, 0xFFFF, 0xFFFF)
err = ioutil.WriteFile(path.Join(dir, large), []byte("bad data"), 0666) err = ioutil.WriteFile(filepath.Join(dir, large), []byte("bad data"), 0666)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -109,7 +109,7 @@ func TestFailback(t *testing.T) {
if !reflect.DeepEqual(g, testSnap) { if !reflect.DeepEqual(g, testSnap) {
t.Errorf("snap = %#v, want %#v", g, testSnap) t.Errorf("snap = %#v, want %#v", g, testSnap)
} }
if f, err := os.Open(path.Join(dir, large) + ".broken"); err != nil { if f, err := os.Open(filepath.Join(dir, large) + ".broken"); err != nil {
t.Fatal("broken snapshot does not exist") t.Fatal("broken snapshot does not exist")
} else { } else {
f.Close() f.Close()
@ -117,7 +117,7 @@ func TestFailback(t *testing.T) {
} }
func TestSnapNames(t *testing.T) { func TestSnapNames(t *testing.T) {
dir := path.Join(os.TempDir(), "snapshot") dir := filepath.Join(os.TempDir(), "snapshot")
err := os.Mkdir(dir, 0700) err := os.Mkdir(dir, 0700)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -125,7 +125,7 @@ func TestSnapNames(t *testing.T) {
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
for i := 1; i <= 5; i++ { for i := 1; i <= 5; i++ {
var f *os.File var f *os.File
if f, err = os.Create(path.Join(dir, fmt.Sprintf("%d.snap", i))); err != nil { if f, err = os.Create(filepath.Join(dir, fmt.Sprintf("%d.snap", i))); err != nil {
t.Fatal(err) t.Fatal(err)
} else { } else {
f.Close() f.Close()
@ -146,7 +146,7 @@ func TestSnapNames(t *testing.T) {
} }
func TestLoadNewestSnap(t *testing.T) { func TestLoadNewestSnap(t *testing.T) {
dir := path.Join(os.TempDir(), "snapshot") dir := filepath.Join(os.TempDir(), "snapshot")
err := os.Mkdir(dir, 0700) err := os.Mkdir(dir, 0700)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -175,7 +175,7 @@ func TestLoadNewestSnap(t *testing.T) {
} }
func TestNoSnapshot(t *testing.T) { func TestNoSnapshot(t *testing.T) {
dir := path.Join(os.TempDir(), "snapshot") dir := filepath.Join(os.TempDir(), "snapshot")
err := os.Mkdir(dir, 0700) err := os.Mkdir(dir, 0700)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -189,19 +189,19 @@ func TestNoSnapshot(t *testing.T) {
} }
func TestEmptySnapshot(t *testing.T) { func TestEmptySnapshot(t *testing.T) {
dir := path.Join(os.TempDir(), "snapshot") dir := filepath.Join(os.TempDir(), "snapshot")
err := os.Mkdir(dir, 0700) err := os.Mkdir(dir, 0700)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
err = ioutil.WriteFile(path.Join(dir, "1.snap"), []byte(""), 0x700) err = ioutil.WriteFile(filepath.Join(dir, "1.snap"), []byte(""), 0x700)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
_, err = Read(path.Join(dir, "1.snap")) _, err = Read(filepath.Join(dir, "1.snap"))
if err != ErrEmptySnapshot { if err != ErrEmptySnapshot {
t.Errorf("err = %v, want %v", err, ErrEmptySnapshot) t.Errorf("err = %v, want %v", err, ErrEmptySnapshot)
} }
@ -210,14 +210,14 @@ func TestEmptySnapshot(t *testing.T) {
// TestAllSnapshotBroken ensures snapshotter returns // TestAllSnapshotBroken ensures snapshotter returns
// ErrNoSnapshot if all the snapshots are broken. // ErrNoSnapshot if all the snapshots are broken.
func TestAllSnapshotBroken(t *testing.T) { func TestAllSnapshotBroken(t *testing.T) {
dir := path.Join(os.TempDir(), "snapshot") dir := filepath.Join(os.TempDir(), "snapshot")
err := os.Mkdir(dir, 0700) err := os.Mkdir(dir, 0700)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
err = ioutil.WriteFile(path.Join(dir, "1.snap"), []byte("bad"), 0x700) err = ioutil.WriteFile(filepath.Join(dir, "1.snap"), []byte("bad"), 0x700)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -18,7 +18,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"log" "log"
"path" "path/filepath"
"time" "time"
"github.com/coreos/etcd/etcdserver/etcdserverpb" "github.com/coreos/etcd/etcdserver/etcdserverpb"
@ -58,7 +58,7 @@ func main() {
ss := snap.New(snapDir(*from)) ss := snap.New(snapDir(*from))
snapshot, err = ss.Load() snapshot, err = ss.Load()
} else { } else {
snapshot, err = snap.Read(path.Join(snapDir(*from), *snapfile)) snapshot, err = snap.Read(filepath.Join(snapDir(*from), *snapfile))
} }
switch err { switch err {
@ -132,9 +132,9 @@ func main() {
} }
} }
func walDir(dataDir string) string { return path.Join(dataDir, "member", "wal") } func walDir(dataDir string) string { return filepath.Join(dataDir, "member", "wal") }
func snapDir(dataDir string) string { return path.Join(dataDir, "member", "snap") } func snapDir(dataDir string) string { return filepath.Join(dataDir, "member", "snap") }
func parseWALMetadata(b []byte) (id, cid types.ID) { func parseWALMetadata(b []byte) (id, cid types.ID) {
var metadata etcdserverpb.Metadata var metadata etcdserverpb.Metadata