forked from TrueCloudLab/restic
pack: Change Finalize() to return uint
This commit is contained in:
parent
1b3d3a7ec2
commit
aeedd2a370
2 changed files with 9 additions and 9 deletions
16
pack/pack.go
16
pack/pack.go
|
@ -108,7 +108,7 @@ func (p *Packer) Add(t BlobType, id backend.ID, rd io.Reader) (int64, error) {
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var entrySize = binary.Size(BlobType(0)) + binary.Size(uint32(0)) + backend.IDSize
|
var entrySize = uint(binary.Size(BlobType(0)) + binary.Size(uint32(0)) + backend.IDSize)
|
||||||
|
|
||||||
// headerEntry is used with encoding/binary to read and write header entries
|
// headerEntry is used with encoding/binary to read and write header entries
|
||||||
type headerEntry struct {
|
type headerEntry struct {
|
||||||
|
@ -121,11 +121,11 @@ type headerEntry struct {
|
||||||
// Returned are the complete number of bytes written, including the header.
|
// Returned are the complete number of bytes written, including the header.
|
||||||
// After Finalize() has finished, the ID of this pack can be obtained by
|
// After Finalize() has finished, the ID of this pack can be obtained by
|
||||||
// calling ID().
|
// calling ID().
|
||||||
func (p *Packer) Finalize() (bytesWritten int64, err error) {
|
func (p *Packer) Finalize() (bytesWritten uint, err error) {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
bytesWritten = int64(p.bytes)
|
bytesWritten = p.bytes
|
||||||
|
|
||||||
// create writer to encrypt header
|
// create writer to encrypt header
|
||||||
wr := crypto.EncryptTo(p.k, p.hw)
|
wr := crypto.EncryptTo(p.k, p.hw)
|
||||||
|
@ -141,27 +141,27 @@ func (p *Packer) Finalize() (bytesWritten int64, err error) {
|
||||||
err := binary.Write(wr, binary.LittleEndian, entry)
|
err := binary.Write(wr, binary.LittleEndian, entry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wr.Close()
|
wr.Close()
|
||||||
return int64(bytesWritten), err
|
return bytesWritten, err
|
||||||
}
|
}
|
||||||
|
|
||||||
bytesWritten += int64(entrySize)
|
bytesWritten += entrySize
|
||||||
}
|
}
|
||||||
|
|
||||||
// finalize encrypted header
|
// finalize encrypted header
|
||||||
err = wr.Close()
|
err = wr.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return int64(bytesWritten), err
|
return bytesWritten, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// account for crypto overhead
|
// account for crypto overhead
|
||||||
bytesWritten += crypto.Extension
|
bytesWritten += crypto.Extension
|
||||||
|
|
||||||
// write length
|
// write length
|
||||||
err = binary.Write(p.hw, binary.LittleEndian, uint32(len(p.blobs)*entrySize+crypto.Extension))
|
err = binary.Write(p.hw, binary.LittleEndian, uint32(uint(len(p.blobs))*entrySize+crypto.Extension))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return bytesWritten, err
|
return bytesWritten, err
|
||||||
}
|
}
|
||||||
bytesWritten += int64(binary.Size(uint32(0)))
|
bytesWritten += uint(binary.Size(uint32(0)))
|
||||||
|
|
||||||
p.bytes = uint(bytesWritten)
|
p.bytes = uint(bytesWritten)
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ func TestCreatePack(t *testing.T) {
|
||||||
written += crypto.Extension
|
written += crypto.Extension
|
||||||
|
|
||||||
// check length
|
// check length
|
||||||
Equals(t, int64(written), n)
|
Equals(t, uint(written), n)
|
||||||
Equals(t, uint(written), p.Size())
|
Equals(t, uint(written), p.Size())
|
||||||
|
|
||||||
// read and parse it again
|
// read and parse it again
|
||||||
|
|
Loading…
Reference in a new issue