@@ -218,13 +218,6 @@ func (as ArtifactStore) Add(ctx context.Context, dest string, artifactBlobs []li
218218 return nil , errors .New ("append option is not compatible with type option" )
219219 }
220220
221- // currently we don't allow override of the filename ; if a user requirement emerges,
222- // we could seemingly accommodate but broadens possibilities of something bad happening
223- // for things like `artifact extract`
224- if _ , hasTitle := options .Annotations [specV1 .AnnotationTitle ]; hasTitle {
225- return nil , fmt .Errorf ("cannot override filename with %s annotation" , specV1 .AnnotationTitle )
226- }
227-
228221 locked := true
229222 as .lock .Lock ()
230223 defer func () {
@@ -317,7 +310,17 @@ func (as ArtifactStore) Add(ctx context.Context, dest string, artifactBlobs []li
317310 }
318311
319312 annotations := maps .Clone (options .Annotations )
320- annotations [specV1 .AnnotationTitle ] = artifactBlob .FileName
313+ if title , ok := annotations [specV1 .AnnotationTitle ]; ok {
314+ // Verify a duplicate AnnotationTitle is not in use in a different layer.
315+ for _ , layer := range artifactManifest .Layers {
316+ if title == layer .Annotations [specV1 .AnnotationTitle ] {
317+ return nil , fmt .Errorf ("duplicate layers %s labels within an artifact not allowed" , specV1 .AnnotationTitle )
318+ }
319+ }
320+ } else {
321+ // Only override if the user did not specify the Title
322+ annotations [specV1 .AnnotationTitle ] = artifactBlob .FileName
323+ }
321324
322325 newLayer := specV1.Descriptor {
323326 MediaType : options .FileMIMEType ,
@@ -469,6 +472,11 @@ func (as ArtifactStore) BlobMountPaths(ctx context.Context, nameOrDigest string,
469472 mountPaths := make ([]libartTypes.BlobMountPath , 0 , len (arty .Manifest .Layers ))
470473 for _ , l := range arty .Manifest .Layers {
471474 title := l .Annotations [specV1 .AnnotationTitle ]
475+ for _ , mp := range mountPaths {
476+ if title == mp .Name {
477+ return nil , fmt .Errorf ("annotation %q:%q is used in multiple different layers within artifact" , specV1 .AnnotationTitle , title )
478+ }
479+ }
472480 filename , err := generateArtifactBlobName (title , l .Digest )
473481 if err != nil {
474482 return nil , err
0 commit comments