X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Flockdir.go;h=a756381bee0f5d353d602112c75080cef0704694;hb=6fc6d4f97d051bb1ff828c74a17939a40a08c66c;hp=f87e6c6afbf67dd132d992b9eb144c1ea4fc8e17;hpb=510478b83a2808262f7167fffe5296b489a2bf03;p=nncp.git diff --git a/src/lockdir.go b/src/lockdir.go index f87e6c6..a756381 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-2020 Sergey Matveev +Copyright (C) 2016-2022 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 @@ -25,7 +25,9 @@ import ( ) func (ctx *Ctx) LockDir(nodeId *NodeId, lockCtx string) (*os.File, error) { - ctx.ensureRxDir(nodeId) + if err := ctx.ensureRxDir(nodeId); err != nil { + return nil, err + } lockPath := filepath.Join(ctx.Spool, nodeId.String(), lockCtx) + ".lock" dirLock, err := os.OpenFile( lockPath, @@ -33,12 +35,16 @@ func (ctx *Ctx) LockDir(nodeId *NodeId, lockCtx string) (*os.File, error) { 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() return nil, err }