@@ -1451,6 +1451,12 @@ func ensureDir(dir string, log zerolog.Logger) error {
14511451 return nil
14521452}
14531453
1454+ type extendedManifest struct {
1455+ ispec.Manifest
1456+
1457+ Digest godigest.Digest
1458+ }
1459+
14541460func (is * ImageStoreLocal ) garbageCollect (dir string , repo string ) error {
14551461 oci , err := umoci .OpenLayout (dir )
14561462 if err := test .Error (err ); err != nil {
@@ -1466,7 +1472,7 @@ func (is *ImageStoreLocal) garbageCollect(dir string, repo string) error {
14661472
14671473 referencedByImageIndex := []string {}
14681474 cosignDescriptors := []ispec.Descriptor {}
1469- notationDescriptors := []ispec. Descriptor {}
1475+ notationManifests := []extendedManifest {}
14701476
14711477 /* gather manifests references by multiarch images (to skip gc)
14721478 gather cosign and notation signatures descriptors */
@@ -1504,7 +1510,10 @@ func (is *ImageStoreLocal) garbageCollect(dir string, repo string) error {
15041510 }
15051511
15061512 if zcommon .GetManifestArtifactType (manifestContent ) == notreg .ArtifactTypeNotation {
1507- notationDescriptors = append (notationDescriptors , desc )
1513+ notationManifests = append (notationManifests , extendedManifest {
1514+ Digest : desc .Digest ,
1515+ Manifest : manifestContent ,
1516+ })
15081517
15091518 continue
15101519 }
@@ -1525,7 +1534,7 @@ func (is *ImageStoreLocal) garbageCollect(dir string, repo string) error {
15251534
15261535 is .log .Info ().Msg ("gc: notation signatures" )
15271536
1528- if err := gcNotationSignatures (is , oci , & index , repo , notationDescriptors ); err != nil {
1537+ if err := gcNotationSignatures (is , oci , & index , repo , notationManifests ); err != nil {
15291538 return err
15301539 }
15311540
@@ -1641,41 +1650,24 @@ func gcCosignSignatures(imgStore *ImageStoreLocal, oci casext.Engine, index *isp
16411650}
16421651
16431652func gcNotationSignatures (imgStore * ImageStoreLocal , oci casext.Engine , index * ispec.Index , repo string ,
1644- notationDescriptors []ispec. Descriptor ,
1653+ notationManifests []extendedManifest ,
16451654) error {
1646- for _ , notationDesc := range notationDescriptors {
1655+ for _ , notationManifest := range notationManifests {
16471656 foundSubject := false
1648- // check if we can find the manifest which the signature points to
1649- var artManifest ispec.Manifest
1650-
1651- buf , err := imgStore .GetBlobContent (repo , notationDesc .Digest )
1652- if err != nil {
1653- imgStore .log .Error ().Err (err ).Str ("repository" , repo ).Str ("digest" , notationDesc .Digest .String ()).
1654- Msg ("gc: failed to get notation manifest" )
1655-
1656- return err
1657- }
1658-
1659- if err := json .Unmarshal (buf , & artManifest ); err != nil {
1660- imgStore .log .Error ().Err (err ).Str ("repository" , repo ).Str ("digest" , notationDesc .Digest .String ()).
1661- Msg ("gc: failed to get notation manifest" )
1662-
1663- return err
1664- }
16651657
16661658 for _ , desc := range index .Manifests {
1667- if desc .Digest == artManifest .Subject .Digest {
1659+ if desc .Digest == notationManifest .Subject .Digest {
16681660 foundSubject = true
16691661 }
16701662 }
16711663
16721664 if ! foundSubject {
16731665 // remove manifest
1674- imgStore .log .Info ().Str ("repository" , repo ).Str ("digest" , notationDesc .Digest .String ()).
1666+ imgStore .log .Info ().Str ("repository" , repo ).Str ("digest" , notationManifest .Digest .String ()).
16751667 Msg ("gc: removing notation signature without subject" )
16761668
16771669 // no need to check for manifest conflict, if one doesn't have a subject, then none with same digest will have
1678- _ , _ = storage .RemoveManifestDescByReference (index , notationDesc .Digest .String (), false )
1670+ _ , _ = storage .RemoveManifestDescByReference (index , notationManifest .Digest .String (), false )
16791671
16801672 err := oci .PutIndex (context .Background (), * index )
16811673 if err != nil {
0 commit comments