2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-22 04:45:15 +00:00

Merge pull request #2638 from greatroar/no-close-in-packer

Don't Close in Packer.Finalize
This commit is contained in:
MichaelEischer 2020-04-18 13:07:21 +02:00 committed by GitHub
commit c4da9d1e90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 13 deletions

View File

@ -25,12 +25,8 @@ type Packer struct {
m sync.Mutex
}
// NewPacker returns a new Packer that can be used to pack blobs
// together. If wr is nil, a bytes.Buffer is used.
// NewPacker returns a new Packer that can be used to pack blobs together.
func NewPacker(k *crypto.Key, wr io.Writer) *Packer {
if wr == nil {
wr = bytes.NewBuffer(nil)
}
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.
// Returned are the number of bytes written, including the header. If the
// underlying writer implements io.Closer, it is closed.
// Returned are the number of bytes written, including the header.
func (p *Packer) Finalize() (uint, error) {
p.m.Lock()
defer p.m.Unlock()
@ -101,11 +96,6 @@ func (p *Packer) Finalize() (uint, error) {
bytesWritten += uint(binary.Size(uint32(0)))
p.bytes = uint(bytesWritten)
if w, ok := p.wr.(io.Closer); ok {
return bytesWritten, w.Close()
}
return bytesWritten, nil
}

View File

@ -36,7 +36,7 @@ func newPack(t testing.TB, k *crypto.Key, lengths []int) ([]Buf, []byte, uint) {
}
// pack blobs
p := pack.NewPacker(k, nil)
p := pack.NewPacker(k, new(bytes.Buffer))
for _, b := range bufs {
p.Add(restic.TreeBlob, b.id, b.data)
}