Commit fa4cfe8d authored by Brian Tiger Chow's avatar Brian Tiger Chow

refactor(init, fsrepo): go through repo to write to config

parent a2d1e339
......@@ -95,11 +95,6 @@ func doInit(configRoot string, dspathOverride string, force bool, nBitsForKeypai
u.POut("initializing ipfs node at %s\n", configRoot)
configFilename, err := config.Filename(configRoot)
if err != nil {
return nil, debugerror.New("Couldn't get home directory path")
}
if fsrepo.ConfigIsInitialized(configRoot) && !force {
return nil, errCannotInitConfigExists
}
......@@ -109,7 +104,14 @@ func doInit(configRoot string, dspathOverride string, force bool, nBitsForKeypai
return nil, err
}
if err := config.WriteConfigFile(configFilename, conf); err != nil {
repo := fsrepo.At(configRoot)
if err := repo.Open(); err != nil {
return nil, err
}
if err := repo.SetConfig(conf); err != nil {
return nil, err
}
if err := repo.Close(); err != nil {
return nil, err
}
......
package fsrepo
import (
"io"
config "github.com/jbenet/go-ipfs/repo/config"
util "github.com/jbenet/go-ipfs/util"
)
type FSRepo struct {
path string
config config.Config
}
func At(path string) *FSRepo {
return &FSRepo{
path: path,
}
}
func (r *FSRepo) Open() error {
// TODO may need to check that directory is writeable
// TODO acquire repo lock
return nil
}
func (r *FSRepo) SetConfig(conf *config.Config) error {
configFilename, err := config.Filename(r.path)
if err != nil {
return err
}
if err := config.WriteConfigFile(configFilename, conf); err != nil {
return err
}
r.config = *conf // copy so caller cannot modify the private config
return nil
}
func (r *FSRepo) Close() error {
return nil // TODO release repo lock
}
var _ io.Closer = &FSRepo{}
// ConfigIsInitialized returns true if the config exists in provided |path|.
func ConfigIsInitialized(path string) bool {
configFilename, err := config.Filename(path)
......
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