Implement creating necessary directories when creating private key file

This commit is contained in:
ChronosX88 2021-07-27 02:03:12 +03:00
parent d179ffcd76
commit 225c84e8a8
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A

View File

@ -8,6 +8,7 @@ import (
"io/ioutil"
"os"
"path"
"path/filepath"
"runtime"
types2 "github.com/Secured-Finance/dione/blockchain/types"
@ -311,6 +312,14 @@ func providePrivateKey(cfg *config.Config) crypto.PrivKey {
logrus.Fatal(err)
}
dirName := filepath.Dir(cfg.PrivateKeyPath)
if _, err := os.Stat(dirName); os.IsNotExist(err) {
err := os.MkdirAll(dirName, 0755)
if err != nil {
logrus.Fatalf("Cannot create private key file: %s", err.Error())
}
}
f, err := os.Create(cfg.PrivateKeyPath)
if err != nil {
logrus.Fatalf("Cannot create private key file: %s, ", err)