mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-09 19:32:24 +08:00

We now consider debugerrors harmful: we've run into cases where debugerror.Wrap() hid valuable error information (err == io.EOF?). I've removed them from the main code, but left them in some tests. Go errors are lacking, but unfortunately, this isn't the solution. It is possible that debugerros.New or debugerrors.Errorf should remain still (i.e. only remove debugerrors.Wrap) but we don't use these errors often enough to keep.
31 lines
618 B
Go
31 lines
618 B
Go
package lock
|
|
|
|
import (
|
|
"io"
|
|
"path"
|
|
|
|
lock "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/camlistore/lock"
|
|
"github.com/ipfs/go-ipfs/util"
|
|
)
|
|
|
|
// LockFile is the filename of the daemon lock, relative to config dir
|
|
// TODO rename repo lock and hide name
|
|
const LockFile = "daemon.lock"
|
|
|
|
func Lock(confdir string) (io.Closer, error) {
|
|
c, err := lock.Lock(path.Join(confdir, LockFile))
|
|
return c, 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
|
|
}
|
|
}
|