fix node/node.go flock dependency

This commit is contained in:
arnaucube
2019-03-18 15:50:15 +01:00
parent fb458280d1
commit 8e5d39923a
3 changed files with 227 additions and 8 deletions

View File

@@ -34,7 +34,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rpc"
"github.com/prometheus/prometheus/util/flock"
"github.com/gofrs/flock"
)
// Node is a container on which services can be registered.
@@ -43,8 +43,8 @@ type Node struct {
config *Config
accman *accounts.Manager
ephemeralKeystore string // if non-empty, the key directory that will be removed by Stop
instanceDirLock flock.Releaser // prevents concurrent use of instance directory
ephemeralKeystore string // if non-empty, the key directory that will be removed by Stop
instanceDirLock *flock.Flock // prevents concurrent use of instance directory
serverConfig p2p.Config
server *p2p.Server // Currently running P2P networking layer
@@ -262,10 +262,7 @@ func (n *Node) openDataDir() error {
}
// Lock the instance directory to prevent concurrent use by another instance as well as
// accidental use of the instance directory as a database.
release, _, err := flock.New(filepath.Join(instdir, "LOCK"))
if err != nil {
return convertFileLockError(err)
}
release := flock.New(filepath.Join(instdir, "LOCK"))
n.instanceDirLock = release
return nil
}
@@ -450,7 +447,7 @@ func (n *Node) Stop() error {
// Release instance directory lock.
if n.instanceDirLock != nil {
if err := n.instanceDirLock.Release(); err != nil {
if err := n.instanceDirLock.Unlock(); err != nil {
n.log.Error("Can't release datadir lock", "err", err)
}
n.instanceDirLock = nil