From fb7860e43f37e8d219ba5d55b609e601f3328c57 Mon Sep 17 00:00:00 2001 From: fearlessfe <505380967@qq.com> Date: Sat, 5 Oct 2024 12:24:51 +0800 Subject: [PATCH] fix: write key error --- cmd/shisui/main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/shisui/main.go b/cmd/shisui/main.go index 3525d3cf65..db5777a310 100644 --- a/cmd/shisui/main.go +++ b/cmd/shisui/main.go @@ -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 {