github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/builder/dockerfile/dispatchers_unix.go (about)

     1  // +build !windows
     2  
     3  package dockerfile
     4  
     5  import (
     6  	"fmt"
     7  	"os"
     8  	"path/filepath"
     9  )
    10  
    11  // normaliseWorkdir normalises a user requested working directory in a
    12  // platform sematically consistent way.
    13  func normaliseWorkdir(current string, requested string) (string, error) {
    14  	if requested == "" {
    15  		return "", fmt.Errorf("cannot normalise nothing")
    16  	}
    17  	current = filepath.FromSlash(current)
    18  	requested = filepath.FromSlash(requested)
    19  	if !filepath.IsAbs(requested) {
    20  		return filepath.Join(string(os.PathSeparator), current, requested), nil
    21  	}
    22  	return requested, nil
    23  }
    24  
    25  func errNotJSON(command, _ string) error {
    26  	return fmt.Errorf("%s requires the arguments to be in JSON form", command)
    27  }