mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 18:13:54 +08:00
const for lock file, + fix unreachable Close
This commit is contained in:
@ -6,11 +6,12 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
core "github.com/jbenet/go-ipfs/core"
|
||||
"github.com/jbenet/go-ipfs/core/commands"
|
||||
u "github.com/jbenet/go-ipfs/util"
|
||||
"github.com/op/go-logging"
|
||||
logging "github.com/op/go-logging"
|
||||
|
||||
"github.com/camlistore/lock"
|
||||
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
|
||||
@ -18,6 +19,9 @@ import (
|
||||
|
||||
var log = logging.MustGetLogger("daemon")
|
||||
|
||||
// LockFile is the filename of the daemon lock, relative to config dir
|
||||
const LockFile = "daemon.lock"
|
||||
|
||||
// DaemonListener listens to an initialized IPFS node and can send it commands instead of
|
||||
// starting up a new set of connections
|
||||
type DaemonListener struct {
|
||||
@ -41,7 +45,7 @@ func NewDaemonListener(ipfsnode *core.IpfsNode, addr *ma.Multiaddr, confdir stri
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lk, err := lock.Lock(confdir + "/daemon.lock")
|
||||
lk, err := daemonLock(confdir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -133,3 +137,7 @@ func (dl *DaemonListener) Close() error {
|
||||
dl.closed = true
|
||||
return dl.list.Close()
|
||||
}
|
||||
|
||||
func daemonLock(confdir string) (io.Closer, error) {
|
||||
return lock.Lock(path.Join(confdir, LockFile))
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"net"
|
||||
"os"
|
||||
|
||||
lock "github.com/camlistore/lock"
|
||||
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
|
||||
|
||||
u "github.com/jbenet/go-ipfs/util"
|
||||
@ -43,10 +42,10 @@ func getDaemonAddr(confdir string) (string, error) {
|
||||
return string(line), nil
|
||||
}
|
||||
|
||||
// SendCommand issues a command (of type daemon.Command) to the daemon, if it
|
||||
// is running (if not, errors out). This is done over network RPC API. The
|
||||
// address of the daemon is retrieved from the configuration directory, where
|
||||
// live daemons write their addresses to special files.
|
||||
// SendCommand attempts to run the command over a currently-running daemon.
|
||||
// If there is no running daemon, returns ErrDaemonNotRunning. This is done
|
||||
// over network RPC API. The address of the daemon is retrieved from the config
|
||||
// directory, where live daemons write their addresses to special files.
|
||||
func SendCommand(command *Command, confdir string) error {
|
||||
//check if daemon is running
|
||||
log.Info("Checking if daemon is running...")
|
||||
@ -55,10 +54,10 @@ func SendCommand(command *Command, confdir string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lk, err := lock.Lock(confdir + "/daemon.lock")
|
||||
lk, err := daemonLock(confdir)
|
||||
if err == nil {
|
||||
return ErrDaemonNotRunning
|
||||
lk.Close()
|
||||
return ErrDaemonNotRunning
|
||||
}
|
||||
|
||||
log.Info("Daemon is running! %s", err)
|
||||
|
Reference in New Issue
Block a user