]> Cypherpunks.ru repositories - nncp.git/commitdiff
More error handling
authorSergey Matveev <stargrave@stargrave.org>
Fri, 26 Apr 2019 19:25:01 +0000 (22:25 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 26 Apr 2019 19:25:01 +0000 (22:25 +0300)
src/cypherpunks.ru/nncp/cmd/nncp-bundle/main.go
src/cypherpunks.ru/nncp/cmd/nncp-reass/main.go
src/cypherpunks.ru/nncp/cmd/nncp-xfer/main.go
src/cypherpunks.ru/nncp/toss.go
src/cypherpunks.ru/nncp/tx.go

index 33d269c79800eafe47c063afd80f763d54b498a2..eaa61a4a8a2434386aa4bd9eda94e53702beac26 100644 (file)
@@ -367,7 +367,9 @@ func main() {
                                        if err = bufTmp.Flush(); err != nil {
                                                log.Fatalln("Error during flushing:", err)
                                        }
-                                       tmp.Sync()
+                                       if err = tmp.Sync(); err != nil {
+                                               log.Fatalln("Error during syncing:", err)
+                                       }
                                        tmp.Close()
                                        if err = os.MkdirAll(selfPath, os.FileMode(0700)); err != nil {
                                                log.Fatalln("Error during mkdir:", err)
index 6a35ab6ba9709b32681b15a4b00054aacae071e0..ea139ce00eb000860c7c00cfdbc9a3329726a06f 100644 (file)
@@ -203,9 +203,13 @@ func process(ctx *nncp.Ctx, path string, keep, dryRun, stdout, dumpMeta bool) bo
                        }
                }
        }
-       dstW.Flush()
+       if err = dstW.Flush(); err != nil {
+               log.Fatalln("Can not flush:", err)
+       }
        if tmp != nil {
-               tmp.Sync()
+               if err = tmp.Sync(); err != nil {
+                       log.Fatalln("Can not sync:", err)
+               }
                tmp.Close()
        }
        ctx.LogD("nncp-reass", sds, "written")
index a8406281dae470368e818150ed5cc24bb433e8d5..b8c6cc675ab1b8782cb429a12cd4076e29564897 100644 (file)
@@ -309,14 +309,19 @@ Tx:
                                isBad = true
                                continue
                        }
-                       err = bufW.Flush()
-                       tmp.Sync()
-                       tmp.Close()
-                       if err != nil {
-                               ctx.LogE("nncp-xfer", nncp.SdsAdd(sds, nncp.SDS{"err": err}), "copy")
+                       if err = bufW.Flush(); err != nil {
+                               tmp.Close()
+                               ctx.LogE("nncp-xfer", nncp.SdsAdd(sds, nncp.SDS{"err": err}), "flush")
                                isBad = true
                                continue
                        }
+                       if err = tmp.Sync(); err != nil {
+                               tmp.Close()
+                               ctx.LogE("nncp-xfer", nncp.SdsAdd(sds, nncp.SDS{"err": err}), "sync")
+                               isBad = true
+                               continue
+                       }
+                       tmp.Close()
                        if err = os.Rename(tmp.Name(), filepath.Join(dstPath, pktName)); err != nil {
                                ctx.LogE("nncp-xfer", nncp.SdsAdd(sds, nncp.SDS{"err": err}), "rename")
                                isBad = true
index 26d655e52668e4b03d2e01153afd9c59e9b80230..bcfeb150f7b44a50155776b65c36f678d711462c 100644 (file)
@@ -189,8 +189,18 @@ func (ctx *Ctx) Toss(
                                        isBad = true
                                        goto Closing
                                }
-                               bufW.Flush()
-                               tmp.Sync()
+                               if err = bufW.Flush(); err != nil {
+                                       tmp.Close()
+                                       ctx.LogE("rx", SdsAdd(sds, SDS{"err": err}), "copy")
+                                       isBad = true
+                                       goto Closing
+                               }
+                               if err = tmp.Sync(); err != nil {
+                                       tmp.Close()
+                                       ctx.LogE("rx", SdsAdd(sds, SDS{"err": err}), "copy")
+                                       isBad = true
+                                       goto Closing
+                               }
                                tmp.Close()
                                dstPathOrig := filepath.Join(*incoming, dst)
                                dstPath := dstPathOrig
index 5fbc9719e62c52c10ad837a8791f9a1b264b9097..260f9bd811ebd6a79599af7204630ceab19f72ff 100644 (file)
@@ -125,7 +125,9 @@ func prepareTxFile(srcPath string) (io.Reader, *os.File, int64, error) {
                        return nil, nil, 0, err
                }
                fileSize = int64(written)
-               tmpW.Flush()
+               if err = tmpW.Flush(); err != nil {
+                       return nil, nil, 0, err
+               }
                src.Seek(0, 0)
                r, w := io.Pipe()
                go ae(tmpKey, bufio.NewReader(src), w)