Ver Fonte

builder/dockerfile: remove fromSlash() and separator() utils

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn há 3 anos atrás
pai
commit
131fac6eb4
2 ficheiros alterados com 6 adições e 29 exclusões
  1. 4 11
      builder/dockerfile/copy.go
  2. 2 18
      builder/dockerfile/internals.go

+ 4 - 11
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

+ 2 - 18
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 '/'
-}