]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cypherpunks.ru/nncp/toss.go
Move lockdir to separate file
[nncp.git] / src / cypherpunks.ru / nncp / toss.go
index 4ae9711f8d7d6f42fbefb50b1363ef3001ccaef6..fec62ae365a2c105e36f40b626298879ee13eca5 100644 (file)
@@ -36,7 +36,6 @@ import (
        "github.com/davecgh/go-xdr/xdr2"
        "github.com/dustin/go-humanize"
        "golang.org/x/crypto/blake2b"
-       "golang.org/x/sys/unix"
 )
 
 func newNotification(fromTo *FromToYAML, subject string) io.Reader {
@@ -48,34 +47,6 @@ func newNotification(fromTo *FromToYAML, subject string) io.Reader {
        ))
 }
 
-func (ctx *Ctx) LockDir(nodeId *NodeId, xx TRxTx) (*os.File, error) {
-       ctx.ensureRxDir(nodeId)
-       lockPath := filepath.Join(ctx.Spool, nodeId.String(), string(xx)) + ".lock"
-       dirLock, err := os.OpenFile(
-               lockPath,
-               os.O_CREATE|os.O_WRONLY,
-               os.FileMode(0600),
-       )
-       if err != nil {
-               ctx.LogE("lockdir", SDS{"path": lockPath, "err": err}, "")
-               return nil, err
-       }
-       err = unix.Flock(int(dirLock.Fd()), unix.LOCK_EX|unix.LOCK_NB)
-       if err != nil {
-               ctx.LogE("lockdir", SDS{"path": lockPath, "err": err}, "")
-               dirLock.Close()
-               return nil, err
-       }
-       return dirLock, nil
-}
-
-func (ctx *Ctx) UnlockDir(fd *os.File) {
-       if fd != nil {
-               unix.Flock(int(fd.Fd()), unix.LOCK_UN)
-               fd.Close()
-       }
-}
-
 func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8, dryRun bool) bool {
        dirLock, err := ctx.LockDir(nodeId, TRx)
        if err != nil {