From: Sergey Matveev Date: Fri, 26 Apr 2019 19:25:01 +0000 (+0300) Subject: More error handling X-Git-Tag: 4.0^2~15 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=4a11fd627bb72b4ebe90a640cc93da7b5f9efea0;p=nncp.git More error handling --- diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-bundle/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-bundle/main.go index 33d269c..eaa61a4 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-bundle/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-bundle/main.go @@ -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) diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-reass/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-reass/main.go index 6a35ab6..ea139ce 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-reass/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-reass/main.go @@ -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") diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-xfer/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-xfer/main.go index a840628..b8c6cc6 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-xfer/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-xfer/main.go @@ -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 diff --git a/src/cypherpunks.ru/nncp/toss.go b/src/cypherpunks.ru/nncp/toss.go index 26d655e..bcfeb15 100644 --- a/src/cypherpunks.ru/nncp/toss.go +++ b/src/cypherpunks.ru/nncp/toss.go @@ -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 diff --git a/src/cypherpunks.ru/nncp/tx.go b/src/cypherpunks.ru/nncp/tx.go index 5fbc971..260f9bd 100644 --- a/src/cypherpunks.ru/nncp/tx.go +++ b/src/cypherpunks.ru/nncp/tx.go @@ -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)