mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-11 07:03:32 +08:00
feat(init): remove datastore path override
This commit is contained in:
@ -35,7 +35,6 @@ var initCmd = &cmds.Command{
|
|||||||
cmds.IntOption("bits", "b", "Number of bits to use in the generated RSA private key (defaults to 4096)"),
|
cmds.IntOption("bits", "b", "Number of bits to use in the generated RSA private key (defaults to 4096)"),
|
||||||
cmds.StringOption("passphrase", "p", "Passphrase for encrypting the private key"),
|
cmds.StringOption("passphrase", "p", "Passphrase for encrypting the private key"),
|
||||||
cmds.BoolOption("force", "f", "Overwrite existing config (if it exists)"),
|
cmds.BoolOption("force", "f", "Overwrite existing config (if it exists)"),
|
||||||
cmds.StringOption("datastore", "d", "Location for the IPFS data store"),
|
|
||||||
|
|
||||||
// TODO need to decide whether to expose the override as a file or a
|
// TODO need to decide whether to expose the override as a file or a
|
||||||
// directory. That is: should we allow the user to also specify the
|
// directory. That is: should we allow the user to also specify the
|
||||||
@ -44,11 +43,6 @@ var initCmd = &cmds.Command{
|
|||||||
},
|
},
|
||||||
Run: func(req cmds.Request) (interface{}, error) {
|
Run: func(req cmds.Request) (interface{}, error) {
|
||||||
|
|
||||||
dspathOverride, _, err := req.Option("d").String() // if !found it's okay. Let == ""
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
force, _, err := req.Option("f").Bool() // if !found, it's okay force == false
|
force, _, err := req.Option("f").Bool() // if !found, it's okay force == false
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -62,7 +56,7 @@ var initCmd = &cmds.Command{
|
|||||||
nBitsForKeypair = nBitsForKeypairDefault
|
nBitsForKeypair = nBitsForKeypairDefault
|
||||||
}
|
}
|
||||||
|
|
||||||
return doInit(req.Context().ConfigRoot, dspathOverride, force, nBitsForKeypair)
|
return doInit(req.Context().ConfigRoot, force, nBitsForKeypair)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,11 +81,11 @@ For a short demo of what you can do, enter 'ipfs tour'
|
|||||||
`
|
`
|
||||||
|
|
||||||
func initWithDefaults(configRoot string) error {
|
func initWithDefaults(configRoot string) error {
|
||||||
_, err := doInit(configRoot, "", false, nBitsForKeypairDefault)
|
_, err := doInit(configRoot, false, nBitsForKeypairDefault)
|
||||||
return debugerror.Wrap(err)
|
return debugerror.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func doInit(configRoot string, dspathOverride string, force bool, nBitsForKeypair int) (interface{}, error) {
|
func doInit(configRoot string, force bool, nBitsForKeypair int) (interface{}, error) {
|
||||||
|
|
||||||
u.POut("initializing ipfs node at %s\n", configRoot)
|
u.POut("initializing ipfs node at %s\n", configRoot)
|
||||||
|
|
||||||
@ -99,7 +93,7 @@ func doInit(configRoot string, dspathOverride string, force bool, nBitsForKeypai
|
|||||||
return nil, errCannotInitConfigExists
|
return nil, errCannotInitConfigExists
|
||||||
}
|
}
|
||||||
|
|
||||||
conf, err := initConfig(dspathOverride, nBitsForKeypair)
|
conf, err := initConfig(nBitsForKeypair)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -151,28 +145,22 @@ func addTheWelcomeFile(conf *config.Config) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func datastoreConfig(dspath string) (config.Datastore, error) {
|
func datastoreConfig() (config.Datastore, error) {
|
||||||
ds := config.Datastore{}
|
ds := config.Datastore{}
|
||||||
if len(dspath) == 0 {
|
dspath, err := config.DataStorePath("")
|
||||||
var err error
|
if err != nil {
|
||||||
dspath, err = config.DataStorePath("")
|
return ds, err
|
||||||
if err != nil {
|
|
||||||
return ds, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ds.Path = dspath
|
ds.Path = dspath
|
||||||
ds.Type = "leveldb"
|
ds.Type = "leveldb"
|
||||||
|
if err := initCheckDir(dspath); err != nil {
|
||||||
err := initCheckDir(dspath)
|
|
||||||
if err != nil {
|
|
||||||
return ds, debugerror.Errorf("datastore: %s", err)
|
return ds, debugerror.Errorf("datastore: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ds, nil
|
return ds, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func initConfig(dspathOverride string, nBitsForKeypair int) (*config.Config, error) {
|
func initConfig(nBitsForKeypair int) (*config.Config, error) {
|
||||||
ds, err := datastoreConfig(dspathOverride)
|
ds, err := datastoreConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user