even more carefullness
@@ -2,13 +2,14 @@ package p2p
import (
"encoding/json"
- "github.com/spacemeshos/go-spacemesh/filesystem"
- "github.com/spacemeshos/go-spacemesh/log"
- "github.com/spacemeshos/go-spacemesh/p2p/nodeconfig"
"io/ioutil"
"os"
"path/filepath"
"strings"
+
+ "github.com/spacemeshos/go-spacemesh/filesystem"
+ "github.com/spacemeshos/go-spacemesh/log"
+ "github.com/spacemeshos/go-spacemesh/p2p/nodeconfig"
)
// NodeData defines persistent node data.
@@ -77,12 +78,12 @@ func (n *localNodeImp) persistData() error {
}
// make sure our node file is written to the os filesystem.
- err = ioutil.WriteFile(path, bytes, filesystem.OwnerReadWrite)
+ f, err := os.Create(path)
if err != nil {
return err
}
- f, err := os.Open(path)
+ _, err = f.Write(bytes)
if err != nil {
return err
}
@@ -92,6 +93,11 @@ func (n *localNodeImp) persistData() error {
return err
}
+ err = f.Close()
+ if err != nil {
+ return err
+ }
+
log.Info("Node data persisted and synced. NodeID ", n.String())
return nil
