mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Windows: Fix absolute checks
Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
parent
26fb160610
commit
49c1b51ae2
5 changed files with 17 additions and 36 deletions
|
@ -15,6 +15,7 @@ import (
|
|||
Cli "github.com/docker/docker/cli"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
)
|
||||
|
||||
type copyDirection int
|
||||
|
@ -101,7 +102,7 @@ func (cli *DockerCli) CmdCp(args ...string) error {
|
|||
// client, a `:` could be part of an absolute Windows path, in which case it
|
||||
// is immediately proceeded by a backslash.
|
||||
func splitCpArg(arg string) (container, path string) {
|
||||
if filepath.IsAbs(arg) {
|
||||
if system.IsAbs(arg) {
|
||||
// Explicit local absolute path, e.g., `C:\foo` or `/foo`.
|
||||
return "", arg
|
||||
}
|
||||
|
@ -236,7 +237,7 @@ func (cli *DockerCli) copyToContainer(srcPath, dstContainer, dstPath string) (er
|
|||
// If the destination is a symbolic link, we should evaluate it.
|
||||
if err == nil && dstStat.Mode&os.ModeSymlink != 0 {
|
||||
linkTarget := dstStat.LinkTarget
|
||||
if !filepath.IsAbs(linkTarget) {
|
||||
if !system.IsAbs(linkTarget) {
|
||||
// Join with the parent directory.
|
||||
dstParent, _ := archive.SplitPathDirEntry(dstPath)
|
||||
linkTarget = filepath.Join(dstParent, linkTarget)
|
||||
|
|
|
@ -10,7 +10,7 @@ package builder
|
|||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
|
@ -21,6 +21,7 @@ import (
|
|||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/pkg/nat"
|
||||
"github.com/docker/docker/pkg/stringutils"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
"github.com/docker/docker/runconfig"
|
||||
)
|
||||
|
||||
|
@ -272,39 +273,15 @@ func workdir(b *builder, args []string, attributes map[string]bool, original str
|
|||
return err
|
||||
}
|
||||
|
||||
// Note that workdir passed comes from the Dockerfile. Hence it is in
|
||||
// Linux format using forward-slashes, even on Windows. However,
|
||||
// b.Config.WorkingDir is in platform-specific notation (in other words
|
||||
// on Windows will use `\`
|
||||
workdir := args[0]
|
||||
// This is from the Dockerfile and will not necessarily be in platform
|
||||
// specific semantics, hence ensure it is converted.
|
||||
workdir := filepath.FromSlash(args[0])
|
||||
|
||||
isAbs := false
|
||||
if runtime.GOOS == "windows" {
|
||||
// Alternate processing for Windows here is necessary as we can't call
|
||||
// filepath.IsAbs(workDir) as that would verify Windows style paths,
|
||||
// along with drive-letters (eg c:\pathto\file.txt). We (arguably
|
||||
// correctly or not) check for both forward and back slashes as this
|
||||
// is what the 1.4.2 GoLang implementation of IsAbs() does in the
|
||||
// isSlash() function.
|
||||
isAbs = workdir[0] == '\\' || workdir[0] == '/'
|
||||
} else {
|
||||
isAbs = filepath.IsAbs(workdir)
|
||||
if !system.IsAbs(workdir) {
|
||||
current := filepath.FromSlash(b.Config.WorkingDir)
|
||||
workdir = filepath.Join(string(os.PathSeparator), current, workdir)
|
||||
}
|
||||
|
||||
if !isAbs {
|
||||
current := b.Config.WorkingDir
|
||||
if runtime.GOOS == "windows" {
|
||||
// Convert to Linux format before join
|
||||
current = strings.Replace(current, "\\", "/", -1)
|
||||
}
|
||||
// Must use path.Join so works correctly on Windows, not filepath
|
||||
workdir = path.Join("/", current, workdir)
|
||||
}
|
||||
|
||||
// Convert to platform specific format
|
||||
if runtime.GOOS == "windows" {
|
||||
workdir = strings.Replace(workdir, "/", "\\", -1)
|
||||
}
|
||||
b.Config.WorkingDir = workdir
|
||||
|
||||
return b.commit("", b.Config.Cmd, fmt.Sprintf("WORKDIR %v", workdir))
|
||||
|
|
|
@ -270,7 +270,7 @@ func calcCopyInfo(b *builder, cmdName string, cInfos *[]*copyInfo, origPath stri
|
|||
|
||||
// Twiddle the destPath when its a relative path - meaning, make it
|
||||
// relative to the WORKINGDIR
|
||||
if !filepath.IsAbs(destPath) {
|
||||
if !system.IsAbs(destPath) {
|
||||
hasSlash := strings.HasSuffix(destPath, string(os.PathSeparator))
|
||||
destPath = filepath.Join(string(os.PathSeparator), filepath.FromSlash(b.Config.WorkingDir), destPath)
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
)
|
||||
|
||||
// Errors used or returned by this file.
|
||||
|
@ -210,7 +211,7 @@ func CopyInfoDestinationPath(path string) (info CopyInfo, err error) {
|
|||
return CopyInfo{}, err
|
||||
}
|
||||
|
||||
if !filepath.IsAbs(linkTarget) {
|
||||
if !system.IsAbs(linkTarget) {
|
||||
// Join with the parent directory.
|
||||
dstParent, _ := SplitPathDirEntry(path)
|
||||
linkTarget = filepath.Join(dstParent, linkTarget)
|
||||
|
|
|
@ -12,6 +12,8 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/pkg/system"
|
||||
)
|
||||
|
||||
// FollowSymlinkInScope is a wrapper around evalSymlinksInScope that returns an
|
||||
|
@ -120,7 +122,7 @@ func evalSymlinksInScope(path, root string) (string, error) {
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if filepath.IsAbs(dest) {
|
||||
if system.IsAbs(dest) {
|
||||
b.Reset()
|
||||
}
|
||||
path = dest + string(filepath.Separator) + path
|
||||
|
|
Loading…
Reference in a new issue