X-Git-Url: http://www.git.cypherpunks.ru/?p=nncp.git;a=blobdiff_plain;f=src%2Fcypherpunks.ru%2Fnncp%2Ftmp.go;h=47a20d0a6e85623ee5774bc6d0f135a325aed119;hp=2ce02cb80dae79a81afa388e5ab27b01c91ce517;hb=6d771479c630cc44a3873ded16ce24f75aadf0fe;hpb=938477682cd6212a88a67c31f46e46c205c7d989 diff --git a/src/cypherpunks.ru/nncp/tmp.go b/src/cypherpunks.ru/nncp/tmp.go index 2ce02cb..47a20d0 100644 --- a/src/cypherpunks.ru/nncp/tmp.go +++ b/src/cypherpunks.ru/nncp/tmp.go @@ -45,7 +45,7 @@ func (ctx *Ctx) NewTmpFile() (*os.File, error) { type TmpFileWHash struct { W *bufio.Writer Fd *os.File - hsh hash.Hash + Hsh hash.Hash ctx *Ctx } @@ -61,7 +61,7 @@ func (ctx *Ctx) NewTmpFileWHash() (*TmpFileWHash, error) { return &TmpFileWHash{ W: bufio.NewWriter(io.MultiWriter(hsh, tmp)), Fd: tmp, - hsh: hsh, + Hsh: hsh, ctx: ctx, }, nil } @@ -81,9 +81,12 @@ func (tmp *TmpFileWHash) Commit(dir string) error { tmp.Fd.Close() return err } - tmp.Fd.Sync() + if err = tmp.Fd.Sync(); err != nil { + tmp.Fd.Close() + return err + } tmp.Fd.Close() - checksum := ToBase32(tmp.hsh.Sum(nil)) + checksum := ToBase32(tmp.Hsh.Sum(nil)) tmp.ctx.LogD("tmp", SDS{"src": tmp.Fd.Name(), "dst": checksum}, "commit") return os.Rename(tmp.Fd.Name(), filepath.Join(dir, checksum)) }