create dir for node keyfile (#2161)

This commit is contained in:
Alex Sharov 2021-06-14 13:35:22 +07:00 committed by GitHub
parent 229d6671b9
commit b79823d1b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -22,6 +22,7 @@ import (
"fmt" "fmt"
"io" "io"
"math/big" "math/big"
"os"
"path" "path"
"path/filepath" "path/filepath"
"strconv" "strconv"
@ -570,6 +571,10 @@ func setNodeKey(ctx *cli.Context, cfg *p2p.Config, nodeName, dataDir string) {
case file != "" && hex != "": case file != "" && hex != "":
Fatalf("Options %q and %q are mutually exclusive", NodeKeyFileFlag.Name, NodeKeyHexFlag.Name) Fatalf("Options %q and %q are mutually exclusive", NodeKeyFileFlag.Name, NodeKeyHexFlag.Name)
case file != "": case file != "":
if err := os.MkdirAll(path.Dir(file), 0755); err != nil {
panic(err)
}
if key, err = crypto.LoadECDSA(file); err != nil { if key, err = crypto.LoadECDSA(file); err != nil {
Fatalf("Option %q: %v", NodeKeyFileFlag.Name, err) Fatalf("Option %q: %v", NodeKeyFileFlag.Name, err)
} }
@ -746,6 +751,9 @@ func NewP2PConfig(nodiscover bool, datadir, netRestrict, natSetting, nodeName st
} }
func nodeKey(keyfile string) *ecdsa.PrivateKey { func nodeKey(keyfile string) *ecdsa.PrivateKey {
if err := os.MkdirAll(path.Dir(keyfile), 0755); err != nil {
panic(err)
}
if key, err := crypto.LoadECDSA(keyfile); err == nil { if key, err := crypto.LoadECDSA(keyfile); err == nil {
return key return key
} }

View File

@ -27,7 +27,6 @@ const expectMdbxVersionMinor = 10
type MdbxOpts struct { type MdbxOpts struct {
inMem bool inMem bool
exclusive bool
label Label // marker to distinct db instances - one process may open many databases. for example to collect metrics of only 1 database label Label // marker to distinct db instances - one process may open many databases. for example to collect metrics of only 1 database
flags uint flags uint
path string path string
@ -63,7 +62,7 @@ func (opts MdbxOpts) InMem() MdbxOpts {
} }
func (opts MdbxOpts) Exclusive() MdbxOpts { func (opts MdbxOpts) Exclusive() MdbxOpts {
opts.exclusive = true opts.flags = opts.flags | mdbx.Exclusive
return opts return opts
} }