@@ -414,32 +414,33 @@ func (s *store) Check(options *CheckOptions) (CheckReport, error) {
414414 }
415415 }
416416 }
417- // Check that we don't have any dangling parent layer references.
418- for id , parent := range report .layerParentsByLayerID {
419- // If this layer doesn't have a parent, no problem.
420- if parent == "" {
421- continue
422- }
423- // If we've already seen a layer with this parent ID, skip it.
424- if _ , checked := referencedLayers [parent ]; checked {
425- continue
426- }
427- if _ , checked := referencedROLayers [parent ]; checked {
428- continue
429- }
430- // We haven't seen a layer with the ID that this layer's record
431- // says is its parent's ID.
432-
433- // Not recordError2 because we are recording for layer "id"
434- // but the text talks about layer "parent".
435- report .recordLayerErrors (id ,
436- fmt .Errorf ("%slayer %s: %w" , readWriteDesc , parent , ErrLayerMissing ))
437- }
438417 return struct {}{}, false , nil
439418 }); err != nil {
440419 return CheckReport {}, err
441420 }
442421
422+ // Check that we don't have any dangling parent layer references.
423+ // This runs after all layer stores (RW and RO) have been visited,
424+ // so both referencedLayers and referencedROLayers are fully populated.
425+ for id , parent := range report .layerParentsByLayerID {
426+ if parent == "" {
427+ continue
428+ }
429+ if _ , checked := referencedLayers [parent ]; checked {
430+ continue
431+ }
432+ if _ , checked := referencedROLayers [parent ]; checked {
433+ continue
434+ }
435+ if _ , isRO := referencedROLayers [id ]; isRO {
436+ report .recordROLayerErrors (id ,
437+ fmt .Errorf ("read-only layer %s: %w" , parent , ErrLayerMissing ))
438+ } else {
439+ report .recordLayerErrors (id ,
440+ fmt .Errorf ("layer %s: %w" , parent , ErrLayerMissing ))
441+ }
442+ }
443+
443444 // This map will track examined images. If we have multiple stores, read-only ones can
444445 // contain copies of images that are also in the read-write store, or the read-write store
445446 // may contain a duplicate entry that refers to layers in the read-only stores, but when
0 commit comments