]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cmd/nncp-xfer/main.go
nncp-xfer compares the checksum
[nncp.git] / src / cmd / nncp-xfer / main.go
index 68aa102aa68970c117444499bf51b90951f75b31..a1ef5fa5d51c438179b33450f7876352d62d5242 100644 (file)
@@ -266,7 +266,7 @@ func main() {
                                fd.Close()
                                continue
                        }
-                       if _, err = fd.Seek(0, 0); err != nil {
+                       if _, err = fd.Seek(0, io.SeekStart); err != nil {
                                log.Fatalln(err)
                        }
                        tmp, err := ctx.NewTmpFileWHash()
@@ -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(