/*
NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2020 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2021 Sergey Matveev <stargrave@stargrave.org>
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
func (ctx *Ctx) LockDir(nodeId *NodeId, lockCtx string) (*os.File, error) {
if err := ctx.ensureRxDir(nodeId); err != nil {
- ctx.LogE("lockdir", SDS{}, err, "")
return nil, err
}
lockPath := filepath.Join(ctx.Spool, nodeId.String(), lockCtx) + ".lock"
os.FileMode(0666),
)
if err != nil {
- ctx.LogE("lockdir", SDS{"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", SDS{"path": lockPath}, err, "")
+ ctx.LogE("lockdir-flock", LEs{{"Path", lockPath}}, err, func(les LEs) string {
+ return "Locking directory: locking " + lockPath
+ })
dirLock.Close() // #nosec G104
return nil, err
}
func (ctx *Ctx) UnlockDir(fd *os.File) {
if fd != nil {
unix.Flock(int(fd.Fd()), unix.LOCK_UN) // #nosec G104
- fd.Close() // #nosec G104
+ fd.Close() // #nosec G104
}
}