mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 09:52:20 +08:00
refactor(init, fsrepo): go through repo to write to config
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,47 @@
|
||||
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)
|
||||
|
Reference in New Issue
Block a user