]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cypherpunks.ru/nncp/tmp.go
Forbid any later GNU GPL versions autousage
[nncp.git] / src / cypherpunks.ru / nncp / tmp.go
index 6cb6723f682de6d0daa16748708b871ddc3dd868..3c305ce36a54d7ec4432d8d98c1c43392a1311a5 100644 (file)
@@ -1,11 +1,10 @@
 /*
-NNCP -- Node-to-Node CoPy
-Copyright (C) 2016-2017 Sergey Matveev <stargrave@stargrave.org>
+NNCP -- Node to Node copy, utilities for store-and-forward data exchange
+Copyright (C) 2016-2019 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
+the Free Software Foundation, version 3 of the License.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -45,7 +44,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 +60,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 +80,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))
 }