Check the datastore is writeable when initializing

上级 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 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论