mirror of
https://github.com/restic/restic.git
synced 2026-08-09 23:23:17 +00:00
repository: merge small pack files before flushing
This prevents chunk size leaks when a backup only consists of a small file which is split in two parts, which end up in two individual pack files.
This commit is contained in:
@@ -163,6 +163,25 @@ func makeHeader(blobs []restic.Blob) ([]byte, error) {
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
func (p *Packer) Merge(other *Packer, otherData io.Reader) error {
|
||||
other.m.Lock()
|
||||
defer other.m.Unlock()
|
||||
|
||||
for _, blob := range other.blobs {
|
||||
data := make([]byte, blob.Length)
|
||||
_, err := io.ReadFull(otherData, data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := p.Add(blob.Type, blob.ID, data, int(blob.UncompressedLength)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Size returns the number of bytes written so far.
|
||||
func (p *Packer) Size() uint {
|
||||
p.m.Lock()
|
||||
|
||||
Reference in New Issue
Block a user