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