github.com/portworx/docker@v1.12.1/builder/dockerfile/internals_unix.go (about)

     1  // +build !windows
     2  
     3  package dockerfile
     4  
     5  import (
     6  	"os"
     7  	"path/filepath"
     8  	"strings"
     9  
    10  	"github.com/docker/docker/pkg/system"
    11  )
    12  
    13  // normaliseDest normalises the destination of a COPY/ADD command in a
    14  // platform semantically consistent way.
    15  func normaliseDest(cmdName, workingDir, requested string) (string, error) {
    16  	dest := filepath.FromSlash(requested)
    17  	endsInSlash := strings.HasSuffix(requested, string(os.PathSeparator))
    18  	if !system.IsAbs(requested) {
    19  		dest = filepath.Join(string(os.PathSeparator), filepath.FromSlash(workingDir), dest)
    20  		// Make sure we preserve any trailing slash
    21  		if endsInSlash {
    22  			dest += string(os.PathSeparator)
    23  		}
    24  	}
    25  	return dest, nil
    26  }