diff --git a/builder/dockerfile/copy.go b/builder/dockerfile/copy.go index 96cd8d5183..d657cfbffb 100644 --- a/builder/dockerfile/copy.go +++ b/builder/dockerfile/copy.go @@ -109,22 +109,15 @@ func copierFromDispatchRequest(req dispatchRequest, download sourceDownloader, i } func (o *copier) createCopyInstruction(sourcesAndDest instructions.SourcesAndDest, cmdName string) (copyInstruction, error) { - inst := copyInstruction{cmdName: cmdName} - - // Work in platform-specific filepath semantics - // TODO: This OS switch for paths is NOT correct and should not be supported. - // Maintained for backwards compatibility - pathOS := runtime.GOOS - if o.platform != nil { - pathOS = o.platform.OS + inst := copyInstruction{ + cmdName: cmdName, + dest: filepath.FromSlash(sourcesAndDest.DestPath), } - inst.dest = fromSlash(sourcesAndDest.DestPath, pathOS) - separator := string(separator(pathOS)) infos, err := o.getCopyInfosForSourcePaths(sourcesAndDest.SourcePaths, inst.dest) if err != nil { return inst, errors.Wrapf(err, "%s failed", cmdName) } - if len(infos) > 1 && !strings.HasSuffix(inst.dest, separator) { + if len(infos) > 1 && !strings.HasSuffix(inst.dest, string(os.PathSeparator)) { return inst, errors.Errorf("When using %s with more than one source file, the destination must be a directory and end with a /", cmdName) } inst.infos = infos diff --git a/builder/dockerfile/internals.go b/builder/dockerfile/internals.go index 77b51d35d9..fec1709b9e 100644 --- a/builder/dockerfile/internals.go +++ b/builder/dockerfile/internals.go @@ -235,8 +235,8 @@ func createDestInfo(workingDir string, inst copyInstruction, rwLayer builder.RWL // normalizeDest normalises the destination of a COPY/ADD command in a // platform semantically consistent way. func normalizeDest(workingDir, requested string, platform string) (string, error) { - dest := fromSlash(requested, platform) - endsInSlash := strings.HasSuffix(dest, string(separator(platform))) + dest := filepath.FromSlash(requested) + endsInSlash := strings.HasSuffix(dest, string(os.PathSeparator)) if platform != "windows" { if !path.IsAbs(requested) { @@ -485,19 +485,3 @@ func hostConfigFromOptions(options *types.ImageBuildOptions) *container.HostConf } return hc } - -// fromSlash works like filepath.FromSlash but with a given OS platform field -func fromSlash(path, platform string) string { - if platform == "windows" { - return strings.Replace(path, "/", "\\", -1) - } - return path -} - -// separator returns a OS path separator for the given OS platform -func separator(platform string) byte { - if platform == "windows" { - return '\\' - } - return '/' -}