forked from TrueCloudLab/restic
Merge pull request #2638 from greatroar/no-close-in-packer
Don't Close in Packer.Finalize
This commit is contained in:
commit
c4da9d1e90
2 changed files with 3 additions and 13 deletions
|
@ -25,12 +25,8 @@ type Packer struct {
|
||||||
m sync.Mutex
|
m sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPacker returns a new Packer that can be used to pack blobs
|
// NewPacker returns a new Packer that can be used to pack blobs together.
|
||||||
// together. If wr is nil, a bytes.Buffer is used.
|
|
||||||
func NewPacker(k *crypto.Key, wr io.Writer) *Packer {
|
func NewPacker(k *crypto.Key, wr io.Writer) *Packer {
|
||||||
if wr == nil {
|
|
||||||
wr = bytes.NewBuffer(nil)
|
|
||||||
}
|
|
||||||
return &Packer{k: k, wr: wr}
|
return &Packer{k: k, wr: wr}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,8 +57,7 @@ type headerEntry struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finalize writes the header for all added blobs and finalizes the pack.
|
// Finalize writes the header for all added blobs and finalizes the pack.
|
||||||
// Returned are the number of bytes written, including the header. If the
|
// Returned are the number of bytes written, including the header.
|
||||||
// underlying writer implements io.Closer, it is closed.
|
|
||||||
func (p *Packer) Finalize() (uint, error) {
|
func (p *Packer) Finalize() (uint, error) {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
@ -101,11 +96,6 @@ func (p *Packer) Finalize() (uint, error) {
|
||||||
bytesWritten += uint(binary.Size(uint32(0)))
|
bytesWritten += uint(binary.Size(uint32(0)))
|
||||||
|
|
||||||
p.bytes = uint(bytesWritten)
|
p.bytes = uint(bytesWritten)
|
||||||
|
|
||||||
if w, ok := p.wr.(io.Closer); ok {
|
|
||||||
return bytesWritten, w.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
return bytesWritten, nil
|
return bytesWritten, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ func newPack(t testing.TB, k *crypto.Key, lengths []int) ([]Buf, []byte, uint) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// pack blobs
|
// pack blobs
|
||||||
p := pack.NewPacker(k, nil)
|
p := pack.NewPacker(k, new(bytes.Buffer))
|
||||||
for _, b := range bufs {
|
for _, b := range bufs {
|
||||||
p.Add(restic.TreeBlob, b.id, b.data)
|
p.Add(restic.TreeBlob, b.id, b.data)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue