github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/engine/builder/dockerfile/dispatchers_unix.go (about)

     1  //go:build !windows
     2  // +build !windows
     3  
     4  package dockerfile // import "github.com/docker/docker/builder/dockerfile"
     5  
     6  import (
     7  	"errors"
     8  	"os"
     9  	"path/filepath"
    10  
    11  	"github.com/docker/docker/api/types/container"
    12  	"github.com/moby/buildkit/frontend/dockerfile/instructions"
    13  )
    14  
    15  // normalizeWorkdir normalizes a user requested working directory in a
    16  // platform semantically consistent way.
    17  func normalizeWorkdir(_ string, current string, requested string) (string, error) {
    18  	if requested == "" {
    19  		return "", errors.New("cannot normalize nothing")
    20  	}
    21  	current = filepath.FromSlash(current)
    22  	requested = filepath.FromSlash(requested)
    23  	if !filepath.IsAbs(requested) {
    24  		return filepath.Join(string(os.PathSeparator), current, requested), nil
    25  	}
    26  	return requested, nil
    27  }
    28  
    29  // resolveCmdLine takes a command line arg set and optionally prepends a platform-specific
    30  // shell in front of it.
    31  func resolveCmdLine(cmd instructions.ShellDependantCmdLine, runConfig *container.Config, os, _, _ string) ([]string, bool) {
    32  	result := cmd.CmdLine
    33  	if cmd.PrependShell && result != nil {
    34  		result = append(getShell(runConfig, os), result...)
    35  	}
    36  	return result, false
    37  }