mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-24 03:47:45 +08:00
cmd/ipfs2: daemon command: Handle lock before initializing node
This commit is contained in:
parent
decda21889
commit
e01f1ba8a1
@ -23,13 +23,6 @@ var daemonCmd = &cmds.Command{
|
||||
func daemonFunc(res cmds.Response, req cmds.Request) {
|
||||
ctx := req.Context()
|
||||
|
||||
node, err := core.NewIpfsNode(ctx.Config, true)
|
||||
if err != nil {
|
||||
res.SetError(err, cmds.ErrNormal)
|
||||
return
|
||||
}
|
||||
ctx.Node = node
|
||||
|
||||
lk, err := daemon.Lock(ctx.ConfigRoot)
|
||||
if err != nil {
|
||||
res.SetError(fmt.Errorf("Couldn't obtain lock. Is another daemon already running?"), cmds.ErrNormal)
|
||||
@ -37,6 +30,13 @@ func daemonFunc(res cmds.Response, req cmds.Request) {
|
||||
}
|
||||
defer lk.Close()
|
||||
|
||||
node, err := core.NewIpfsNode(ctx.Config, true)
|
||||
if err != nil {
|
||||
res.SetError(err, cmds.ErrNormal)
|
||||
return
|
||||
}
|
||||
ctx.Node = node
|
||||
|
||||
addr, err := ma.NewMultiaddr(ctx.Config.Addresses.API)
|
||||
if err != nil {
|
||||
res.SetError(err, cmds.ErrNormal)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user