snap: separate different sections in the filename by adding dash

release-2.0
Xiang Li 2014-08-19 17:03:21 -07:00 committed by Yicheng Qin
parent f7417cf693
commit 3b2a90e775
2 changed files with 3 additions and 3 deletions

View File

@ -31,7 +31,7 @@ func New(dir string) *Snapshotter {
}
func (s *Snapshotter) Save(snapshot *raft.Snapshot) error {
n := fmt.Sprintf("%016x%016x%016x.snap", snapshot.ClusterId, snapshot.Term, snapshot.Index)
fname := fmt.Sprintf("%016x-%016x-%016x.snap", snapshot.ClusterId, snapshot.Term, snapshot.Index)
// TODO(xiangli): make raft.Snapshot a protobuf type
b, err := json.Marshal(snapshot)
if err != nil {
@ -43,7 +43,7 @@ func (s *Snapshotter) Save(snapshot *raft.Snapshot) error {
if err != nil {
return err
}
return ioutil.WriteFile(path.Join(s.dir, n), d, 0666)
return ioutil.WriteFile(path.Join(s.dir, fname), d, 0666)
}
func (s *Snapshotter) Load() (*raft.Snapshot, error) {

View File

@ -64,7 +64,7 @@ func TestFailback(t *testing.T) {
os.Mkdir(dir, 0700)
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)
if err != nil {
t.Fatal(err)