From c967d634bee0e3e52cc5cf447ffd75a522146571 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 5 Jun 2026 13:18:59 +0200 Subject: [PATCH] repository: add PackBlob.UncompressedCiphertextLength() --- cmd/restic/cmd_stats.go | 5 ++--- internal/repository/pack/blob.go | 4 ++++ internal/repository/pack/packedblob.go | 6 ++++++ internal/restic/blob.go | 2 ++ internal/restorer/filerestorer_test.go | 2 ++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/cmd/restic/cmd_stats.go b/cmd/restic/cmd_stats.go index 63ffd6d2a..0e09ae49b 100644 --- a/cmd/restic/cmd_stats.go +++ b/cmd/restic/cmd_stats.go @@ -11,7 +11,6 @@ import ( "time" "github.com/restic/chunker" - "github.com/restic/restic/internal/crypto" "github.com/restic/restic/internal/data" "github.com/restic/restic/internal/global" "github.com/restic/restic/internal/repository" @@ -168,10 +167,10 @@ func runStats(ctx context.Context, opts StatsOptions, gopts global.Options, args } stats.TotalSize += uint64(pbs[0].CiphertextLength()) if repo.Config().Version >= 2 { - stats.TotalUncompressedSize += uint64(crypto.CiphertextLength(int(pbs[0].PlaintextLength()))) + stats.TotalUncompressedSize += uint64(pbs[0].UncompressedCiphertextLength()) if pbs[0].IsCompressed() { stats.TotalCompressedBlobsSize += uint64(pbs[0].CiphertextLength()) - stats.TotalCompressedBlobsUncompressedSize += uint64(crypto.CiphertextLength(int(pbs[0].PlaintextLength()))) + stats.TotalCompressedBlobsUncompressedSize += uint64(pbs[0].UncompressedCiphertextLength()) } } stats.TotalBlobCount++ diff --git a/internal/repository/pack/blob.go b/internal/repository/pack/blob.go index 5ec8e6680..5c7e92a62 100644 --- a/internal/repository/pack/blob.go +++ b/internal/repository/pack/blob.go @@ -27,6 +27,10 @@ func (b Blob) DataLength() uint { return uint(crypto.PlaintextLength(int(b.Length))) } +func (b Blob) UncompressedCiphertextLength() uint { + return uint(crypto.CiphertextLength(int(b.DataLength()))) +} + func (b Blob) IsCompressed() bool { return b.UncompressedLength != 0 } diff --git a/internal/repository/pack/packedblob.go b/internal/repository/pack/packedblob.go index e5d3e3588..b71e2a4ce 100644 --- a/internal/repository/pack/packedblob.go +++ b/internal/repository/pack/packedblob.go @@ -8,12 +8,18 @@ type PackedBlob struct { Blob Blob } +var _ restic.PackBlob = (*PackedBlob)(nil) + func (pb *PackedBlob) PackID() restic.ID { return pb.Pack } func (pb *PackedBlob) Handle() restic.BlobHandle { return pb.Blob.BlobHandle } func (pb *PackedBlob) CiphertextLength() uint { return pb.Blob.Length } +func (pb *PackedBlob) UncompressedCiphertextLength() uint { + return pb.Blob.UncompressedCiphertextLength() +} + func (pb *PackedBlob) PlaintextLength() uint { return pb.Blob.DataLength() } func (pb *PackedBlob) IsCompressed() bool { return pb.Blob.IsCompressed() } diff --git a/internal/restic/blob.go b/internal/restic/blob.go index 5fad7b3f6..c19fb6592 100644 --- a/internal/restic/blob.go +++ b/internal/restic/blob.go @@ -14,6 +14,8 @@ type PackBlob interface { Handle() BlobHandle // CiphertextLength is the encrypted size stored in the pack. CiphertextLength() uint + // UncompressedCiphertextLength is the encrypted size of the uncompressed blob. + UncompressedCiphertextLength() uint // PlaintextLength is the size after decryption/decompression. PlaintextLength() uint IsCompressed() bool diff --git a/internal/restorer/filerestorer_test.go b/internal/restorer/filerestorer_test.go index d517a741d..389604726 100644 --- a/internal/restorer/filerestorer_test.go +++ b/internal/restorer/filerestorer_test.go @@ -47,6 +47,8 @@ func (pb *testPackBlob) Handle() restic.BlobHandle { return pb.handle } func (pb *testPackBlob) CiphertextLength() uint { return pb.ciphertext } +func (pb *testPackBlob) UncompressedCiphertextLength() uint { return pb.ciphertext } + func (pb *testPackBlob) PlaintextLength() uint { return pb.plaintext } func (pb *testPackBlob) IsCompressed() bool { return pb.compressed }