/*
-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
type TmpFileWHash struct {
W *bufio.Writer
Fd *os.File
- hsh hash.Hash
+ Hsh hash.Hash
ctx *Ctx
}
return &TmpFileWHash{
W: bufio.NewWriter(io.MultiWriter(hsh, tmp)),
Fd: tmp,
- hsh: hsh,
+ Hsh: hsh,
ctx: ctx,
}, nil
}
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))
}