@@ -178,11 +178,19 @@ def robosign_ostree(args, s3, build, gpgkey):
178
178
# We've validated the commit, now re-export the repo
179
179
ostree_image = build ['images' ]['ostree' ]
180
180
exported_ostree_path = os .path .join (builddir , ostree_image ['path' ])
181
+ exported_ostree_ref = f'oci-archive:{ exported_ostree_path } :latest'
181
182
# Files stored in the build directory are mode 0600 to prevent
182
183
# accidental mutation. Remove the existing one because otherwise
183
184
# we'll try to `open(O_TRUNC)` it and fail.
184
185
os .unlink (exported_ostree_path )
185
- subprocess .check_call (['ostree' , 'container' , 'export' , '--repo=tmp/repo' , checksum , f'oci-archive:{ exported_ostree_path } :latest' ])
186
+ # Detect and use the replace-detached-metadata API only if available
187
+ verb = "replace-detached-metadata"
188
+ tmp_image = 'tmp.ociarchive'
189
+ if subprocess .check_output (['ostree' , 'container' , 'image' , '--help' ]).find (verb ) >= 0 :
190
+ subprocess .check_call (['ostree' , 'container' , 'image' , verb , f'--src={ exported_ostree_ref } ' , f'--dest=oci-archive:{ tmp_image } :latest' , metapath ])
191
+ os .rename (tmp_image , exported_ostree_path )
192
+ else :
193
+ subprocess .check_call (['ostree' , 'container' , 'export' , '--repo=tmp/repo' , checksum , exported_ostree_ref ])
186
194
# Finalize the export by making it not writable.
187
195
os .chmod (exported_ostree_path , 0o400 )
188
196
ostree_image ['size' ] = os .path .getsize (exported_ostree_path )
0 commit comments