From 2cad23b498bbb9fc1e929b4900b40e520017c614 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Wed, 2 Mar 2022 12:44:24 +0300 Subject: [PATCH] nncp-xfer compares the checksum --- doc/news.ru.texi | 4 ++++ doc/news.texi | 4 ++++ src/cmd/nncp-xfer/main.go | 19 +++++++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/doc/news.ru.texi b/doc/news.ru.texi index 76ebe57..9b19a52 100644 --- a/doc/news.ru.texi +++ b/doc/news.ru.texi @@ -5,6 +5,10 @@ @subsection Релиз 8.6.0 @itemize +@item +@command{nncp-xfer} проверяет сходится ли контрольная сумма +скопированного локально пакета и исходного. + @item Появилась возможность отключения @code{fsync} операции @env{$NNCPNOSYNC=1} переменной окружения. diff --git a/doc/news.texi b/doc/news.texi index 93edf29..03c7197 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -8,6 +8,10 @@ See also this page @ref{Новости, on russian}. @section Release 8.6.0 @itemize +@item +@command{nncp-xfer} checks if locally copied packet's checksum differs +from the source's one. + @item Ability to turn @code{fsync} operation off using @env{$NNCPNOSYNC=1} environment variable. diff --git a/src/cmd/nncp-xfer/main.go b/src/cmd/nncp-xfer/main.go index a349ea2..a1ef5fa 100644 --- a/src/cmd/nncp-xfer/main.go +++ b/src/cmd/nncp-xfer/main.go @@ -284,7 +284,7 @@ func main() { w.CloseWithError(err) } }() - if _, err = nncp.CopyProgressed( + _, err = nncp.CopyProgressed( tmp.W, r, "Rx", append( les, @@ -292,13 +292,24 @@ func main() { nncp.LE{K: "FullSize", V: fiInt.Size()}, ), ctx.ShowPrgrs, - ); err != nil { + ) + fd.Close() + if err != nil { ctx.LogE("xfer-rx", les, err, logMsg) + tmp.Cancel() isBad = true + continue } - fd.Close() - if isBad { + if err = tmp.W.Flush(); err != nil { + ctx.LogE("xfer-rx", les, err, logMsg) + tmp.Cancel() + isBad = true + continue + } + if tmp.Checksum() != fiInt.Name() { + ctx.LogE("xfer-rx", les, errors.New("checksum mismatch"), logMsg) tmp.Cancel() + isBad = true continue } if err = tmp.Commit(filepath.Join( -- 2.44.0