Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init Fix #49

Merged
merged 3 commits into from
Sep 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions cmd/ipfs/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
`
Expand Down
5 changes: 5 additions & 0 deletions config/serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down