Skip to content

Commit

Permalink
Merge pull request #183 from fearlessfe/hot-fix-key
Browse files Browse the repository at this point in the history
fix: write key error
  • Loading branch information
r4f4ss authored Oct 10, 2024
2 parents 7c23e82 + c5bba83 commit c1ed669
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cmd/shisui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,25 @@ 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) {
err := os.MkdirAll(config.DataDir, os.ModePerm)
if err != nil {
log.Error("Failed to create directory:", "err", err)
}
file, err := os.Create(fullPath)
if err != nil {
log.Error("Failed to create file:", "err", err)
}
defer file.Close()
}
log.Info("Creating new private key")
privateKey, err = crypto.GenerateKey()
if err != nil {
Expand Down

0 comments on commit c1ed669

Please sign in to comment.