Commit 76b9a99e authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

Merge pull request #49 from mappum/feat/init-fix

Init Fix
parents 677d790f fbec9798
......@@ -32,9 +32,13 @@ func init() {
}
func initCmd(c *commander.Command, inp []string) error {
_, err := os.Lstat(config.DefaultConfigFilePath)
filename, err := config.Filename(config.DefaultConfigFilePath)
if err != nil {
return errors.New("Couldn't get home directory path")
}
fi, err := os.Lstat(filename)
force := c.Flag.Lookup("f").Value.Get().(bool)
if err != nil && !force {
if fi != nil || (err != nil && !os.IsNotExist(err)) && !force {
return errors.New("ipfs configuration file already exists!\nReinitializing would overwrite your keys.\n(use -f to force overwrite)")
}
cfg := new(config.Config)
......
......@@ -34,12 +34,13 @@ type Config struct {
Peers []*SavedPeer
}
var DefaultConfigFilePath = "~/.go-ipfs/config"
var DefaultConfigFile = `{
const DefaultPathRoot = "~/.go-ipfs"
const DefaultConfigFilePath = DefaultPathRoot + "/config"
const DefaultConfigFile = `{
"identity": {},
"datastore": {
"type": "leveldb",
"path": "~/.go-ipfs/datastore"
"path": "` + DefaultPathRoot + `/datastore"
}
}
`
......
......@@ -22,6 +22,11 @@ func ReadConfigFile(filename string, cfg interface{}) error {
// WriteConfigFile writes the config from `cfg` into `filename`.
func WriteConfigFile(filename string, cfg interface{}) error {
err := os.MkdirAll(filepath.Dir(filename), 0775)
if err != nil {
return err
}
f, err := os.Create(filename)
if err != nil {
return err
......
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