containers / image

Work with containers' images
Apache License 2.0
842 stars 365 forks source link

copy: avoid rewriting list manifest containing unknown fields #2465

Open AlbanBedel opened 3 days ago

AlbanBedel commented 3 days ago

When copying a list manifest we currently create a new one and compare its serialized version to the re-serialized version of the original manifest. If they are identical we then use the original manifest to keep the same digest.

But if the original manifest contains unhandled fields, like artifactType or subject currently, the copy will always differ. As a result we always write a new version without these fields.

We probably can't assume that any new field defined in the future can always be copied as is into another manifest. So using the serialized copy for comparison will always keep creating issues when new fields are defined.

Instead explicitly check for the relevant fields, that is the media type and list of instances. If these have not changed we can use the original manifest without having to care about any additional fields it might be using.

This is a first fix for issue #2460 to generally fix the case where the manifest can be left untouched. The artifactType field should still be copied in most other cases but I don't really know in which direction the internal API should go to handle that. It might also make sense to have some warning when rewriting a manifest and some field from the original one are ignored.