@@ -307,9 +307,6 @@ func (s *storageImageSource) LayerInfosForCopy(ctx context.Context, instanceDige
307
307
if err != nil {
308
308
return nil , fmt .Errorf ("reading layer %q in image %q: %w" , layerID , s .image .ID , err )
309
309
}
310
- if layer .UncompressedSize < 0 {
311
- layer .UncompressedSize = - 1
312
- }
313
310
314
311
blobDigest := layer .UncompressedDigest
315
312
if blobDigest == "" {
@@ -331,12 +328,16 @@ func (s *storageImageSource) LayerInfosForCopy(ctx context.Context, instanceDige
331
328
return nil , fmt .Errorf ("parsing expected diffID %q for layer %q: %w" , expectedDigest , layerID , err )
332
329
}
333
330
}
331
+ size := layer .UncompressedSize
332
+ if size < 0 {
333
+ size = - 1
334
+ }
334
335
s .getBlobMutex .Lock ()
335
336
s .getBlobMutexProtected .digestToLayerID [blobDigest ] = layer .ID
336
337
s .getBlobMutex .Unlock ()
337
338
blobInfo := types.BlobInfo {
338
339
Digest : blobDigest ,
339
- Size : layer . UncompressedSize ,
340
+ Size : size ,
340
341
MediaType : uncompressedLayerType ,
341
342
}
342
343
physicalBlobInfos = append ([]types.BlobInfo {blobInfo }, physicalBlobInfos ... )
@@ -455,10 +456,13 @@ func (s *storageImageSource) getSize() (int64, error) {
455
456
if (layer .TOCDigest == "" && layer .UncompressedDigest == "" ) || (layer .TOCDigest == "" && layer .UncompressedSize < 0 ) {
456
457
return - 1 , fmt .Errorf ("size for layer %q is unknown, failing getSize()" , layerID )
457
458
}
458
- if layer .UncompressedSize < 0 {
459
- sum = 0
459
+ // FIXME: We allow layer.UncompressedSize < 0 above, because currently images in an Additional Layer Store don’t provide that value.
460
+ // Right now, various callers in Podman (and, also, newImage in this package) don’t expect the size computation to fail.
461
+ // Should we update the callers, or do we need to continue returning inaccurate information here? Or should we pay the cost
462
+ // to compute the size from the diff?
463
+ if layer .UncompressedSize >= 0 {
464
+ sum += layer .UncompressedSize
460
465
}
461
- sum += layer .UncompressedSize
462
466
if layer .Parent == "" {
463
467
break
464
468
}
0 commit comments