From: Sergey Matveev Date: Sat, 3 Jul 2021 16:09:17 +0000 (+0300) Subject: Do not shadow return error in TxExec X-Git-Tag: v7.1.0^2~4 X-Git-Url: http://www.git.cypherpunks.ru/?p=nncp.git;a=commitdiff_plain;h=0205ca061cae5e983e94e47ddec047a27079978c Do not shadow return error in TxExec --- diff --git a/doc/news.ru.texi b/doc/news.ru.texi index 967f868..7257baf 100644 --- a/doc/news.ru.texi +++ b/doc/news.ru.texi @@ -9,6 +9,9 @@ Исправлена работоспособность @command{nncp-file} и @command{nncp-exec} команд использующих временный файл (stdin и @option{-use-tmp}). +@item +Исправлен пропадающий плохой код возврата в @command{nncp-exec} команде. + @item Исправлено некорректное генерирование @file{.hdr} при использовании транзитных пакетов. diff --git a/doc/news.texi b/doc/news.texi index 160fd39..b4dd9b1 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -11,6 +11,9 @@ See also this page @ref{Новости, on russian}. Fixed workability of @command{nncp-file} and @command{nncp-exec} commands, that use temporary file (stdin and @option{-use-tmp}). +@item +Fixed disappearing bad return code in @command{nncp-exec} command. + @item Fixed invalid @file{.hdr} generation when transitional packets are used. diff --git a/src/tx.go b/src/tx.go index 681f978..a3f44fe 100644 --- a/src/tx.go +++ b/src/tx.go @@ -690,9 +690,9 @@ func (ctx *Ctx) TxExec( if noCompress { pktType = PktTypeExecFat } - pkt, err := NewPkt(pktType, replyNice, bytes.Join(path, []byte{0})) - if err != nil { - return err + pkt, rerr := NewPkt(pktType, replyNice, bytes.Join(path, []byte{0})) + if rerr != nil { + return rerr } var size int64 @@ -713,15 +713,15 @@ func (ctx *Ctx) TxExec( return err } size = int64(compressed.Len()) - _, err = ctx.Tx(node, pkt, nice, size, minSize, &compressed, handle, areaId) + _, rerr = ctx.Tx(node, pkt, nice, size, minSize, &compressed, handle, areaId) } if noCompress && !useTmp { var data bytes.Buffer - if _, err = io.Copy(&data, in); err != nil { + if _, err := io.Copy(&data, in); err != nil { return err } size = int64(data.Len()) - _, err = ctx.Tx(node, pkt, nice, size, minSize, &data, handle, areaId) + _, rerr = ctx.Tx(node, pkt, nice, size, minSize, &data, handle, areaId) } if !noCompress && useTmp { r, w := io.Pipe() @@ -752,7 +752,7 @@ func (ctx *Ctx) TxExec( return err } size = fileSize - _, err = ctx.Tx(node, pkt, nice, size, minSize, tmpReader, handle, areaId) + _, rerr = ctx.Tx(node, pkt, nice, size, minSize, tmpReader, handle, areaId) } if noCompress && useTmp { tmpReader, closer, fileSize, err := throughTmpFile(in) @@ -763,7 +763,7 @@ func (ctx *Ctx) TxExec( return err } size = fileSize - _, err = ctx.Tx(node, pkt, nice, size, minSize, tmpReader, handle, areaId) + _, rerr = ctx.Tx(node, pkt, nice, size, minSize, tmpReader, handle, areaId) } dst := strings.Join(append([]string{handle}, args...), " ") @@ -781,12 +781,12 @@ func (ctx *Ctx) TxExec( ctx.NodeName(node.Id), dst, humanize.IBytes(uint64(size)), ) } - if err == nil { + if rerr == nil { ctx.LogI("tx", les, logMsg) } else { - ctx.LogE("tx", les, err, logMsg) + ctx.LogE("tx", les, rerr, logMsg) } - return err + return rerr } func (ctx *Ctx) TxTrns(node *Node, nice uint8, size int64, src io.Reader) error {