@@ -361,8 +361,7 @@ func joinExcludePatternWithCopySource(srcNorm, excl string) string {
361361 if srcNorm == "." {
362362 return excl
363363 }
364- if strings .HasPrefix (excl , "!" ) {
365- rest := strings .TrimPrefix (excl , "!" )
364+ if rest , ok := strings .CutPrefix (excl , "!" ); ok {
366365 if rest == "" {
367366 return excl
368367 }
@@ -840,11 +839,12 @@ func (s *stageExecutor) Run(run imagebuilder.Run, config docker.Config) error {
840839 args = []string {run .Files [0 ].Data }
841840 }
842841 } else {
843- full := args [0 ]
842+ var full strings.Builder
843+ full .WriteString (args [0 ])
844844 for _ , file := range run .Files {
845- full += file .Data + "\n " + file .Name
845+ full . WriteString ( file .Data + "\n " + file .Name )
846846 }
847- args = []string {full }
847+ args = []string {full . String () }
848848 }
849849 }
850850 stageMountPoints , err := s .runStageMountPoints (slices .Concat (run .Mounts , s .executor .transientRunMounts ))
@@ -2045,7 +2045,7 @@ func (s *stageExecutor) getCreatedBy(node *parser.Node, addedContentSummary stri
20452045 case "RUN" :
20462046 shArg := ""
20472047 buildArgs := s .getBuildArgsResolvedForRun ()
2048- appendCheckSum := ""
2048+ var appendCheckSum strings. Builder
20492049 for _ , flag := range node .Flags {
20502050 var err error
20512051 mountOptionSource := ""
@@ -2108,7 +2108,7 @@ func (s *stageExecutor) getCreatedBy(node *parser.Node, addedContentSummary stri
21082108 }
21092109 if mountCheckSum != "" {
21102110 // add a separator to appendCheckSum
2111- appendCheckSum += ":" + mountCheckSum
2111+ appendCheckSum . WriteString ( ":" + mountCheckSum )
21122112 }
21132113 }
21142114 if len (node .Original ) > 4 {
@@ -2126,7 +2126,7 @@ func (s *stageExecutor) getCreatedBy(node *parser.Node, addedContentSummary stri
21262126 if buildArgs != "" {
21272127 result = result + "|" + strconv .Itoa (len (strings .Split (buildArgs , " " ))) + " " + buildArgs + " "
21282128 }
2129- result = result + "/bin/sh -c " + shArg + heredoc + appendCheckSum + labelsAndAnnotations
2129+ result = result + "/bin/sh -c " + shArg + heredoc + appendCheckSum . String () + labelsAndAnnotations
21302130 return result , nil
21312131 case "ADD" , "COPY" :
21322132 destination := node
@@ -2804,9 +2804,9 @@ func (s *stageExecutor) EnsureContainerPathAs(path, user string, mode *os.FileMo
28042804// flag set differently should be reflected in its result. Some build settings
28052805// only take affect at the final step, so only note those when they're applied.
28062806func (s * stageExecutor ) buildMetadata (isLastStep bool , isAddOrCopy bool ) string {
2807- unsetLabels := ""
2807+ var unsetLabels strings. Builder
28082808 inheritLabels := ""
2809- unsetAnnotations := ""
2809+ var unsetAnnotations strings. Builder
28102810 inheritAnnotations := ""
28112811 newAnnotations := ""
28122812 layerMutations := ""
@@ -2817,12 +2817,12 @@ func (s *stageExecutor) buildMetadata(isLastStep bool, isAddOrCopy bool) string
28172817 }
28182818 // If --unsetlabel was used to clear a label, make a note of it.
28192819 for _ , label := range s .executor .unsetLabels {
2820- unsetLabels += "|unsetLabel=" + label
2820+ unsetLabels . WriteString ( "|unsetLabel=" + label )
28212821 }
28222822 if isLastStep {
28232823 // If --unsetannotation was used to clear an annotation, make a note of it.
28242824 for _ , annotation := range s .executor .unsetAnnotations {
2825- unsetAnnotations += "|unsetAnnotation=" + annotation
2825+ unsetAnnotations . WriteString ( "|unsetAnnotation=" + annotation )
28262826 }
28272827 // If --inherit-annotation was manually set to false then we cleared the inherited annotations.
28282828 if s .executor .inheritAnnotations == types .OptionalBoolFalse {
@@ -2855,7 +2855,7 @@ func (s *stageExecutor) buildMetadata(isLastStep bool, isAddOrCopy bool) string
28552855 }
28562856
28572857 if isAddOrCopy {
2858- return unsetLabels + " " + inheritLabels + " " + unsetAnnotations + " " + inheritAnnotations + " " + layerMutations + " " + newAnnotations
2858+ return unsetLabels . String () + " " + inheritLabels + " " + unsetAnnotations . String () + " " + inheritAnnotations + " " + layerMutations + " " + newAnnotations
28592859 }
2860- return unsetLabels + inheritLabels + unsetAnnotations + inheritAnnotations + layerMutations + newAnnotations
2860+ return unsetLabels . String () + inheritLabels + unsetAnnotations . String () + inheritAnnotations + layerMutations + newAnnotations
28612861}
0 commit comments