Przeglądaj źródła

snap: separate different sections in the filename by adding dash

Xiang Li 11 lat temu
rodzic
commit
3b2a90e775
2 zmienionych plików z 3 dodań i 3 usunięć
  1. 2 2
      snap/snapshotter.go
  2. 1 1
      snap/snapshotter_test.go

+ 2 - 2
snap/snapshotter.go

@@ -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) {

+ 1 - 1
snap/snapshotter_test.go

@@ -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)