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:
Michael Eischer
2025-03-23 12:29:16 +01:00
parent 62453f9356
commit 8d2d50d095
4 changed files with 124 additions and 9 deletions
+19
View File
@@ -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()