diff --git a/internal/pack/pack.go b/internal/pack/pack.go index 7ac06db72..11be41697 100644 --- a/internal/pack/pack.go +++ b/internal/pack/pack.go @@ -157,6 +157,13 @@ func (p *Packer) Count() int { return len(p.blobs) } +// HeaderFull returns true if the pack header is full. +func (p *Packer) HeaderFull() bool { + p.m.Lock() + defer p.m.Unlock() + return headerSize+uint(len(p.blobs)+1)*entrySize > MaxHeaderSize +} + // Blobs returns the slice of blobs that have been written. func (p *Packer) Blobs() []restic.Blob { p.m.Lock() diff --git a/internal/repository/packer_manager.go b/internal/repository/packer_manager.go index 6179aab5c..e83bf8769 100644 --- a/internal/repository/packer_manager.go +++ b/internal/repository/packer_manager.go @@ -87,8 +87,8 @@ func (r *packerManager) SaveBlob(ctx context.Context, t restic.BlobType, id rest return 0, err } - // if the pack is not full enough, put back to the list - if packer.Size() < r.packSize { + // if the pack and header is not full enough, put back to the list + if packer.Size() < r.packSize && !packer.HeaderFull() { debug.Log("pack is not full enough (%d bytes)", packer.Size()) return size, nil }