@cryptotaxi247 / kubo / commits / 3f4da97c5

cmd/ipfs: Use daemon lock functions

Matt Bell committed Oct 27, 2014 at 17:50 UTC 3f4da97c58e613cf015ef56cc0e4b2a130686100
2 files changed +4 -29
cmd/ipfs/daemon.go
+2 -12
@@ -4,18 +4,14 @@ import (
4 "fmt"
5 "net/http"
6
7 - "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/camlistore/lock"
7 ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
8 manet "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr/net"
9
10 cmds "github.com/jbenet/go-ipfs/commands"
11 cmdsHttp "github.com/jbenet/go-ipfs/commands/http"
13 - "github.com/jbenet/go-ipfs/config"
12 + "github.com/jbenet/go-ipfs/daemon"
13 )
14
16 -// DaemonLockFile is the filename of the daemon lock, relative to config dir
17 -const DaemonLockFile = "daemon.lock"
18 -
15 var Daemon = &cmds.Command{
16 Options: []cmds.Option{},
17 Help: "TODO",
@@ -26,13 +22,7 @@ var Daemon = &cmds.Command{
22 func daemonFunc(req cmds.Request, res cmds.Response) {
23 ctx := req.Context()
24
29 - lockPath, err := config.Path(ctx.ConfigRoot, DaemonLockFile)
30 - if err != nil {
31 - res.SetError(err, cmds.ErrNormal)
32 - return
33 - }
34 -
35 - lk, err := lock.Lock(lockPath)
25 + lk, err := daemon.Lock(ctx.ConfigRoot)
26 if err != nil {
27 res.SetError(fmt.Errorf("Couldn't obtain lock. Is another daemon already running?"), cmds.ErrNormal)
28 return
cmd/ipfs/ipfs.go
+2 -17
@@ -6,13 +6,12 @@ import (
6 "os"
7 "runtime/pprof"
8
9 - "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/camlistore/lock"
10 -
9 cmds "github.com/jbenet/go-ipfs/commands"
10 cmdsCli "github.com/jbenet/go-ipfs/commands/cli"
11 cmdsHttp "github.com/jbenet/go-ipfs/commands/http"
12 "github.com/jbenet/go-ipfs/config"
13 "github.com/jbenet/go-ipfs/core/commands"
14 + "github.com/jbenet/go-ipfs/daemon"
15 u "github.com/jbenet/go-ipfs/util"
16 )
17
@@ -88,21 +87,7 @@ func main() {
87 res = root.Call(req)
88
89 } else {
91 - local := true
92 -
93 - lockFilePath, err := config.Path(configPath, DaemonLockFile)
94 - if err != nil {
95 - fmt.Println(err)
96 - os.Exit(1)
97 - }
98 -
99 - if lk, err := lock.Lock(lockFilePath); err != nil {
100 - local = false
101 - } else {
102 - lk.Close()
103 - }
104 -
105 - if !local {
90 + if daemon.Locked(configPath) {
91 res, err = cmdsHttp.Send(req)
92 if err != nil {
93 fmt.Println(err)