-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
daemon.go
31 lines (25 loc) · 648 Bytes
/
daemon.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package daemon
import (
"io"
"path"
lock "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/camlistore/lock"
"github.com/jbenet/go-ipfs/util"
"github.com/jbenet/go-ipfs/util/debugerror"
)
// LockFile is the filename of the daemon lock, relative to config dir
const LockFile = "daemon.lock"
func Lock(confdir string) (io.Closer, error) {
c, err := lock.Lock(path.Join(confdir, LockFile))
return c, debugerror.Wrap(err)
}
func Locked(confdir string) bool {
if !util.FileExists(path.Join(confdir, LockFile)) {
return false
}
if lk, err := Lock(confdir); err != nil {
return true
} else {
lk.Close()
return false
}
}