Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chunked: report the correct size #1523

Merged
merged 1 commit into from
Feb 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions pkg/chunked/storage_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1302,10 +1302,13 @@ func (c *chunkedDiffer) ApplyDiff(dest string, options *archive.TarOptions) (gra

var missingParts []missingPart

mergedEntries, err := c.mergeTocEntries(c.fileType, toc.Entries)
mergedEntries, totalSize, err := c.mergeTocEntries(c.fileType, toc.Entries)
if err != nil {
return output, err
}

output.Size = totalSize

if err := maybeDoIDRemap(mergedEntries, options); err != nil {
return output, err
}
Expand Down Expand Up @@ -1589,7 +1592,9 @@ func mustSkipFile(fileType compressedFileType, e internal.FileMetadata) bool {
return false
}

func (c *chunkedDiffer) mergeTocEntries(fileType compressedFileType, entries []internal.FileMetadata) ([]internal.FileMetadata, error) {
func (c *chunkedDiffer) mergeTocEntries(fileType compressedFileType, entries []internal.FileMetadata) ([]internal.FileMetadata, int64, error) {
var totalFilesSize int64

countNextChunks := func(start int) int {
count := 0
for _, e := range entries[start:] {
Expand Down Expand Up @@ -1618,8 +1623,11 @@ func (c *chunkedDiffer) mergeTocEntries(fileType compressedFileType, entries []i
if mustSkipFile(fileType, e) {
continue
}

totalFilesSize += e.Size

if e.Type == TypeChunk {
return nil, fmt.Errorf("chunk type without a regular file")
return nil, -1, fmt.Errorf("chunk type without a regular file")
}

if e.Type == TypeReg {
Expand Down Expand Up @@ -1652,7 +1660,7 @@ func (c *chunkedDiffer) mergeTocEntries(fileType compressedFileType, entries []i
lastChunkOffset = mergedEntries[i].Chunks[j].Offset
}
}
return mergedEntries, nil
return mergedEntries, totalFilesSize, nil
}

// validateChunkChecksum checks if the file at $root/$path[offset:chunk.ChunkSize] has the
Expand Down