@@ -483,8 +483,7 @@ func (c Config) expandTargets(pattern string) ([]string, error) {
483483func (c Config ) loadLinks (name string , t * Target , m map [string ]* Target , o map [string ]map [string ]Override , visited []string , ent * EntitlementConf ) error {
484484 visited = append (visited , name )
485485 for _ , v := range t .Contexts {
486- if strings .HasPrefix (v , "target:" ) {
487- target := strings .TrimPrefix (v , "target:" )
486+ if target , ok := strings .CutPrefix (v , "target:" ); ok {
488487 if target == name {
489488 return errors .Errorf ("target %s cannot link to itself" , target )
490489 }
@@ -1275,8 +1274,8 @@ func collectLocalPaths(t build.Inputs) []string {
12751274 if v , ok := isLocalPath (t .DockerfilePath ); ok {
12761275 out = append (out , v )
12771276 }
1278- } else if strings .HasPrefix (t .ContextPath , "cwd://" ) {
1279- out = append (out , strings . TrimPrefix ( t . ContextPath , "cwd://" ) )
1277+ } else if v , ok := strings .CutPrefix (t .ContextPath , "cwd://" ); ok {
1278+ out = append (out , v )
12801279 }
12811280 for _ , v := range t .NamedContexts {
12821281 if v .State != nil {
@@ -1328,11 +1327,11 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
13281327 bi .DockerfileInline = * t .DockerfileInline
13291328 }
13301329 updateContext (& bi , inp )
1331- if strings .HasPrefix (bi .DockerfilePath , "cwd://" ) {
1330+ if v , ok := strings .CutPrefix (bi .DockerfilePath , "cwd://" ); ok {
13321331 // If Dockerfile is local for a remote invocation, we first check if
13331332 // it's not outside the working directory and then resolve it to an
13341333 // absolute path.
1335- bi .DockerfilePath = path .Clean (strings . TrimPrefix ( bi . DockerfilePath , "cwd://" ) )
1334+ bi .DockerfilePath = path .Clean (v )
13361335 var err error
13371336 bi .DockerfilePath , err = filepath .Abs (bi .DockerfilePath )
13381337 if err != nil {
@@ -1357,15 +1356,15 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
13571356 return nil , errors .Errorf ("reading a dockerfile for a remote build invocation is currently not supported" )
13581357 }
13591358 }
1360- if strings .HasPrefix (bi .ContextPath , "cwd://" ) {
1361- bi .ContextPath = path .Clean (strings . TrimPrefix ( bi . ContextPath , "cwd://" ) )
1359+ if v , ok := strings .CutPrefix (bi .ContextPath , "cwd://" ); ok {
1360+ bi .ContextPath = path .Clean (v )
13621361 }
13631362 if ! build .IsRemoteURL (bi .ContextPath ) && bi .ContextState == nil && ! filepath .IsAbs (bi .DockerfilePath ) {
13641363 bi .DockerfilePath = filepath .Join (bi .ContextPath , bi .DockerfilePath )
13651364 }
13661365 for k , v := range bi .NamedContexts {
1367- if strings .HasPrefix (v .Path , "cwd://" ) {
1368- bi .NamedContexts [k ] = build.NamedContext {Path : path .Clean (strings . TrimPrefix ( v . Path , "cwd://" ) )}
1366+ if v , ok := strings .CutPrefix (v .Path , "cwd://" ); ok {
1367+ bi .NamedContexts [k ] = build.NamedContext {Path : path .Clean (v )}
13691368 }
13701369 }
13711370
0 commit comments