mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-24 11:57:44 +08:00
fix: do not create and print out an unused new peerID when initializing from a config
This commit is contained in:
parent
af089dee35
commit
91c1aaa1b5
@ -250,14 +250,20 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
|
||||
}
|
||||
}
|
||||
|
||||
identity, err := config.CreateIdentity(os.Stdout, []options.KeyGenerateOption{
|
||||
options.Key.Type(algorithmDefault),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
if conf == nil {
|
||||
identity, err := config.CreateIdentity(os.Stdout, []options.KeyGenerateOption{
|
||||
options.Key.Type(algorithmDefault),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
conf, err = config.InitWithIdentity(identity)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err = doInit(os.Stdout, cctx.ConfigRoot, false, &identity, profiles, conf); err != nil {
|
||||
if err = doInit(os.Stdout, cctx.ConfigRoot, false, profiles, conf); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,24 +113,30 @@ environment variable:
|
||||
}
|
||||
}
|
||||
|
||||
var err error
|
||||
var identity config.Identity
|
||||
if nBitsGiven {
|
||||
identity, err = config.CreateIdentity(os.Stdout, []options.KeyGenerateOption{
|
||||
options.Key.Size(nBitsForKeypair),
|
||||
options.Key.Type(algorithm),
|
||||
})
|
||||
} else {
|
||||
identity, err = config.CreateIdentity(os.Stdout, []options.KeyGenerateOption{
|
||||
options.Key.Type(algorithm),
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
if conf == nil {
|
||||
var err error
|
||||
var identity config.Identity
|
||||
if nBitsGiven {
|
||||
identity, err = config.CreateIdentity(os.Stdout, []options.KeyGenerateOption{
|
||||
options.Key.Size(nBitsForKeypair),
|
||||
options.Key.Type(algorithm),
|
||||
})
|
||||
} else {
|
||||
identity, err = config.CreateIdentity(os.Stdout, []options.KeyGenerateOption{
|
||||
options.Key.Type(algorithm),
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
conf, err = config.InitWithIdentity(identity)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
profiles, _ := req.Options[profileOptionName].(string)
|
||||
return doInit(os.Stdout, cctx.ConfigRoot, empty, &identity, profiles, conf)
|
||||
return doInit(os.Stdout, cctx.ConfigRoot, empty, profiles, conf)
|
||||
},
|
||||
}
|
||||
|
||||
@ -152,7 +158,7 @@ func applyProfiles(conf *config.Config, profiles string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func doInit(out io.Writer, repoRoot string, empty bool, identity *config.Identity, confProfiles string, conf *config.Config) error {
|
||||
func doInit(out io.Writer, repoRoot string, empty bool, confProfiles string, conf *config.Config) error {
|
||||
if _, err := fmt.Fprintf(out, "initializing IPFS node at %s\n", repoRoot); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -165,18 +171,6 @@ func doInit(out io.Writer, repoRoot string, empty bool, identity *config.Identit
|
||||
return errRepoExists
|
||||
}
|
||||
|
||||
if identity == nil {
|
||||
return fmt.Errorf("No Identity provided for initialization")
|
||||
}
|
||||
|
||||
if conf == nil {
|
||||
var err error
|
||||
conf, err = config.InitWithIdentity(*identity)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := applyProfiles(conf, confProfiles); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user