X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Flockdir.go;h=1e4e39498fb50e9bdba3e83b128eff2eb73fb576;hb=cf9363f956cb2d93a581c11ed65c5b02910d10d5;hp=2e6ac204048ff360982392477337b3d0ea6e6516;hpb=ff2139ccf41d72a3c1c4b56c2106effd1ef2e841;p=nncp.git diff --git a/src/lockdir.go b/src/lockdir.go index 2e6ac20..1e4e394 100644 --- a/src/lockdir.go +++ b/src/lockdir.go @@ -1,6 +1,6 @@ /* NNCP -- Node to Node copy, utilities for store-and-forward data exchange -Copyright (C) 2016-2021 Sergey Matveev +Copyright (C) 2016-2023 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,7 +26,6 @@ import ( func (ctx *Ctx) LockDir(nodeId *NodeId, lockCtx string) (*os.File, error) { if err := ctx.ensureRxDir(nodeId); err != nil { - ctx.LogE("lockdir", LEs{}, err, "") return nil, err } lockPath := filepath.Join(ctx.Spool, nodeId.String(), lockCtx) + ".lock" @@ -36,13 +35,17 @@ func (ctx *Ctx) LockDir(nodeId *NodeId, lockCtx string) (*os.File, error) { os.FileMode(0666), ) if err != nil { - ctx.LogE("lockdir", LEs{{"path", lockPath}}, err, "") + ctx.LogE("lockdir-open", LEs{{"Path", lockPath}}, err, func(les LEs) string { + return "Locking directory: opening " + lockPath + }) return nil, err } err = unix.Flock(int(dirLock.Fd()), unix.LOCK_EX|unix.LOCK_NB) if err != nil { - ctx.LogE("lockdir", LEs{{"path", lockPath}}, err, "") - dirLock.Close() // #nosec G104 + ctx.LogE("lockdir-flock", LEs{{"Path", lockPath}}, err, func(les LEs) string { + return "Locking directory: locking " + lockPath + }) + dirLock.Close() return nil, err } return dirLock, nil @@ -50,7 +53,7 @@ func (ctx *Ctx) LockDir(nodeId *NodeId, lockCtx string) (*os.File, error) { func (ctx *Ctx) UnlockDir(fd *os.File) { if fd != nil { - unix.Flock(int(fd.Fd()), unix.LOCK_UN) // #nosec G104 - fd.Close() // #nosec G104 + unix.Flock(int(fd.Fd()), unix.LOCK_UN) + fd.Close() } }