/*
NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2019 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2020 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
nice uint8,
dryRun, doSeen, noFile, noFreq, noExec, noTrns bool,
) bool {
+ dirLock, err := ctx.LockDir(nodeId, "toss")
+ if err != nil {
+ ctx.LogE("rx", SDS{}, err, "lock")
+ return false
+ }
+ defer ctx.UnlockDir(dirLock)
isBad := false
sendmail := ctx.Neigh[*ctx.SelfId].Exec["sendmail"]
decompressor, err := zstd.NewReader(nil)
continue
}
pipeR, pipeW := io.Pipe()
- errs := make(chan error, 1)
- go func(job Job) {
+ go func(job Job) error {
pipeWB := bufio.NewWriter(pipeW)
_, _, err := PktEncRead(
ctx.Self,
bufio.NewReader(job.Fd),
pipeWB,
)
- errs <- err
- pipeWB.Flush()
- pipeW.Close()
- job.Fd.Close()
+ job.Fd.Close() // #nosec G104
if err != nil {
ctx.LogE("rx", sds, err, "decryption")
+ return pipeW.CloseWithError(err)
+ }
+ if err = pipeWB.Flush(); err != nil {
+ ctx.LogE("rx", sds, err, "decryption flush")
+ return pipeW.CloseWithError(err)
}
+ return pipeW.Close()
}(job)
var pkt Pkt
var err error
cmd.Stdin = newNotification(notify, fmt.Sprintf(
"Exec from %s: %s", sender.Name, argsStr,
), output)
- cmd.Run()
+ if err = cmd.Run(); err != nil {
+ ctx.LogE("rx", sds, err, "notify")
+ }
}
}
}
if !dryRun {
if doSeen {
if fd, err := os.Create(job.Fd.Name() + SeenSuffix); err == nil {
- fd.Close()
+ fd.Close() // #nosec G104
}
}
if err = os.Remove(job.Fd.Name()); err != nil {
goto Closing
}
if err = bufW.Flush(); err != nil {
- tmp.Close()
+ tmp.Close() // #nosec G104
ctx.LogE("rx", sds, err, "copy")
isBad = true
goto Closing
}
if err = tmp.Sync(); err != nil {
- tmp.Close()
+ tmp.Close() // #nosec G104
+ ctx.LogE("rx", sds, err, "copy")
+ isBad = true
+ goto Closing
+ }
+ if err = tmp.Close(); err != nil {
ctx.LogE("rx", sds, err, "copy")
isBad = true
goto Closing
}
- tmp.Close()
dstPathOrig := filepath.Join(*incoming, dst)
dstPath := dstPathOrig
dstPathCtr := 0
if !dryRun {
if doSeen {
if fd, err := os.Create(job.Fd.Name() + SeenSuffix); err == nil {
- fd.Close()
+ fd.Close() // #nosec G104
}
}
if err = os.Remove(job.Fd.Name()); err != nil {
dst,
humanize.IBytes(uint64(pktSize)),
), nil)
- cmd.Run()
+ if err = cmd.Run(); err != nil {
+ ctx.LogE("rx", sds, err, "notify")
+ }
}
}
case PktTypeFreq:
if !dryRun {
if doSeen {
if fd, err := os.Create(job.Fd.Name() + SeenSuffix); err == nil {
- fd.Close()
+ fd.Close() // #nosec G104
}
}
if err = os.Remove(job.Fd.Name()); err != nil {
cmd.Stdin = newNotification(ctx.NotifyFreq, fmt.Sprintf(
"Freq from %s: %s", sender.Name, src,
), nil)
- cmd.Run()
+ if err = cmd.Run(); err != nil {
+ ctx.LogE("rx", sds, err, "notify")
+ }
}
}
case PktTypeTrns:
if !dryRun {
if doSeen {
if fd, err := os.Create(job.Fd.Name() + SeenSuffix); err == nil {
- fd.Close()
+ fd.Close() // #nosec G104
}
}
if err = os.Remove(job.Fd.Name()); err != nil {
isBad = true
}
Closing:
- pipeR.Close()
+ pipeR.Close() // #nosec G104
}
return isBad
}