From 225c84e8a85fd8f5ff4b070ae8726845c4c866ac Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Tue, 27 Jul 2021 02:03:12 +0300 Subject: [PATCH] Implement creating necessary directories when creating private key file --- node/node_dep_providers.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/node/node_dep_providers.go b/node/node_dep_providers.go index 93f9b0e..25616be 100644 --- a/node/node_dep_providers.go +++ b/node/node_dep_providers.go @@ -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)