Check the datastore is writeable when initializing

parent dc1aafba
......@@ -2,6 +2,7 @@ package main
import (
"encoding/base64"
"path/filepath"
"errors"
"os"
......@@ -71,6 +72,18 @@ func initCmd(c *commander.Command, inp []string) error {
cfg.Datastore.Path = dspath
cfg.Datastore.Type = "leveldb"
// Construct the data store if missing
if err := os.MkdirAll(dspath, os.ModeDir); err != nil {
return err
}
// Check the directory is writeable
if f, err := os.Create(filepath.Join(dspath, "._check_writeable")); err == nil {
os.Remove(f.Name())
} else {
return errors.New("Datastore '" + dspath + "' is not writeable")
}
cfg.Identity = config.Identity{}
// setup the node addresses.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment