fix: write key error

This commit is contained in:
fearlessfe 2024-10-05 12:24:51 +08:00
parent d831ad6c25
commit fb7860e43f

View file

@ -498,13 +498,21 @@ func setPrivateKey(ctx *cli.Context, config *Config) error {
return err
}
} else {
if _, err := os.Stat(filepath.Join(config.DataDir, privateKeyFileName)); err == nil {
fullPath := filepath.Join(config.DataDir, privateKeyFileName)
if _, err := os.Stat(fullPath); err == nil {
log.Info("Loading private key from file", "datadir", config.DataDir, "file", privateKeyFileName)
privateKey, err = readPrivateKey(config, privateKeyFileName)
if err != nil {
return err
}
} else {
if os.IsNotExist(err) {
file, err := os.Create(fullPath)
if err != nil {
log.Error("Failed to create file: %v", err)
}
defer file.Close()
}
log.Info("Creating new private key")
privateKey, err = crypto.GenerateKey()
if err != nil {