builder/dockerfile: remove fromSlash() and separator() utils
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
190b6f64e3
commit
131fac6eb4
2 changed files with 6 additions and 29 deletions
|
@ -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
|
||||
|
|
|
@ -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 '/'
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue