@@ -89,7 +89,8 @@ type chunkedDiffer struct {
89
89
// is no TOC referenced by the manifest.
90
90
blobDigest digest.Digest
91
91
92
- blobSize int64
92
+ blobSize int64
93
+ uncompressedTarSize int64 // -1 if unknown
93
94
94
95
pullOptions map [string ]string
95
96
@@ -216,6 +217,7 @@ func makeConvertFromRawDiffer(store storage.Store, blobDigest digest.Digest, blo
216
217
fsVerityDigests : make (map [string ]string ),
217
218
blobDigest : blobDigest ,
218
219
blobSize : blobSize ,
220
+ uncompressedTarSize : - 1 , // Will be computed later
219
221
convertToZstdChunked : true ,
220
222
copyBuffer : makeCopyBuffer (),
221
223
layersCache : layersCache ,
@@ -229,24 +231,33 @@ func makeZstdChunkedDiffer(store storage.Store, blobSize int64, tocDigest digest
229
231
if err != nil {
230
232
return nil , fmt .Errorf ("read zstd:chunked manifest: %w" , err )
231
233
}
234
+ var uncompressedTarSize int64 = - 1
235
+ if tarSplit != nil {
236
+ uncompressedTarSize , err = tarSizeFromTarSplit (tarSplit )
237
+ if err != nil {
238
+ return nil , fmt .Errorf ("computing size from tar-split" )
239
+ }
240
+ }
241
+
232
242
layersCache , err := getLayersCache (store )
233
243
if err != nil {
234
244
return nil , err
235
245
}
236
246
237
247
return & chunkedDiffer {
238
- fsVerityDigests : make (map [string ]string ),
239
- blobSize : blobSize ,
240
- tocDigest : tocDigest ,
241
- copyBuffer : makeCopyBuffer (),
242
- fileType : fileTypeZstdChunked ,
243
- layersCache : layersCache ,
244
- manifest : manifest ,
245
- toc : toc ,
246
- pullOptions : pullOptions ,
247
- stream : iss ,
248
- tarSplit : tarSplit ,
249
- tocOffset : tocOffset ,
248
+ fsVerityDigests : make (map [string ]string ),
249
+ blobSize : blobSize ,
250
+ uncompressedTarSize : uncompressedTarSize ,
251
+ tocDigest : tocDigest ,
252
+ copyBuffer : makeCopyBuffer (),
253
+ fileType : fileTypeZstdChunked ,
254
+ layersCache : layersCache ,
255
+ manifest : manifest ,
256
+ toc : toc ,
257
+ pullOptions : pullOptions ,
258
+ stream : iss ,
259
+ tarSplit : tarSplit ,
260
+ tocOffset : tocOffset ,
250
261
}, nil
251
262
}
252
263
@@ -261,16 +272,17 @@ func makeEstargzChunkedDiffer(store storage.Store, blobSize int64, tocDigest dig
261
272
}
262
273
263
274
return & chunkedDiffer {
264
- fsVerityDigests : make (map [string ]string ),
265
- blobSize : blobSize ,
266
- tocDigest : tocDigest ,
267
- copyBuffer : makeCopyBuffer (),
268
- fileType : fileTypeEstargz ,
269
- layersCache : layersCache ,
270
- manifest : manifest ,
271
- pullOptions : pullOptions ,
272
- stream : iss ,
273
- tocOffset : tocOffset ,
275
+ fsVerityDigests : make (map [string ]string ),
276
+ blobSize : blobSize ,
277
+ uncompressedTarSize : - 1 , // We would have to read and decompress the whole layer
278
+ tocDigest : tocDigest ,
279
+ copyBuffer : makeCopyBuffer (),
280
+ fileType : fileTypeEstargz ,
281
+ layersCache : layersCache ,
282
+ manifest : manifest ,
283
+ pullOptions : pullOptions ,
284
+ stream : iss ,
285
+ tocOffset : tocOffset ,
274
286
}, nil
275
287
}
276
288
@@ -1153,7 +1165,6 @@ func (c *chunkedDiffer) ApplyDiff(dest string, options *archive.TarOptions, diff
1153
1165
1154
1166
var compressedDigest digest.Digest
1155
1167
var uncompressedDigest digest.Digest
1156
- var convertedBlobSize int64
1157
1168
1158
1169
if c .convertToZstdChunked {
1159
1170
fd , err := unix .Open (dest , unix .O_TMPFILE | unix .O_RDWR | unix .O_CLOEXEC , 0o600 )
@@ -1185,7 +1196,7 @@ func (c *chunkedDiffer) ApplyDiff(dest string, options *archive.TarOptions, diff
1185
1196
if err != nil {
1186
1197
return graphdriver.DriverWithDifferOutput {}, err
1187
1198
}
1188
- convertedBlobSize = tarSize
1199
+ c . uncompressedTarSize = tarSize
1189
1200
// fileSource is a O_TMPFILE file descriptor, so we
1190
1201
// need to keep it open until the entire file is processed.
1191
1202
defer fileSource .Close ()
@@ -1255,6 +1266,7 @@ func (c *chunkedDiffer) ApplyDiff(dest string, options *archive.TarOptions, diff
1255
1266
TOCDigest : c .tocDigest ,
1256
1267
UncompressedDigest : uncompressedDigest ,
1257
1268
CompressedDigest : compressedDigest ,
1269
+ Size : c .uncompressedTarSize ,
1258
1270
}
1259
1271
1260
1272
// When the hard links deduplication is used, file attributes are ignored because setting them
@@ -1268,19 +1280,12 @@ func (c *chunkedDiffer) ApplyDiff(dest string, options *archive.TarOptions, diff
1268
1280
1269
1281
var missingParts []missingPart
1270
1282
1271
- mergedEntries , totalSizeFromTOC , err := c .mergeTocEntries (c .fileType , toc .Entries )
1283
+ mergedEntries , err := c .mergeTocEntries (c .fileType , toc .Entries )
1272
1284
if err != nil {
1273
1285
return output , err
1274
1286
}
1275
1287
1276
1288
output .UIDs , output .GIDs = collectIDs (mergedEntries )
1277
- if convertedBlobSize > 0 {
1278
- // if the image was converted, store the original tar size, so that
1279
- // it can be recreated correctly.
1280
- output .Size = convertedBlobSize
1281
- } else {
1282
- output .Size = totalSizeFromTOC
1283
- }
1284
1289
1285
1290
if err := maybeDoIDRemap (mergedEntries , options ); err != nil {
1286
1291
return output , err
@@ -1597,9 +1602,7 @@ func mustSkipFile(fileType compressedFileType, e internal.FileMetadata) bool {
1597
1602
return false
1598
1603
}
1599
1604
1600
- func (c * chunkedDiffer ) mergeTocEntries (fileType compressedFileType , entries []internal.FileMetadata ) ([]fileMetadata , int64 , error ) {
1601
- var totalFilesSize int64
1602
-
1605
+ func (c * chunkedDiffer ) mergeTocEntries (fileType compressedFileType , entries []internal.FileMetadata ) ([]fileMetadata , error ) {
1603
1606
countNextChunks := func (start int ) int {
1604
1607
count := 0
1605
1608
for _ , e := range entries [start :] {
@@ -1629,10 +1632,8 @@ func (c *chunkedDiffer) mergeTocEntries(fileType compressedFileType, entries []i
1629
1632
continue
1630
1633
}
1631
1634
1632
- totalFilesSize += e .Size
1633
-
1634
1635
if e .Type == TypeChunk {
1635
- return nil , - 1 , fmt .Errorf ("chunk type without a regular file" )
1636
+ return nil , fmt .Errorf ("chunk type without a regular file" )
1636
1637
}
1637
1638
1638
1639
if e .Type == TypeReg {
@@ -1668,7 +1669,7 @@ func (c *chunkedDiffer) mergeTocEntries(fileType compressedFileType, entries []i
1668
1669
lastChunkOffset = mergedEntries [i ].chunks [j ].Offset
1669
1670
}
1670
1671
}
1671
- return mergedEntries , totalFilesSize , nil
1672
+ return mergedEntries , nil
1672
1673
}
1673
1674
1674
1675
// validateChunkChecksum checks if the file at $root/$path[offset:chunk.ChunkSize] has the
0 commit comments