mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #15871 from Microsoft/10662-absolute
Windows: Fix absolute checks
This commit is contained in:
commit
2093616d7f
5 changed files with 17 additions and 36 deletions
|
@ -15,6 +15,7 @@ import (
|
||||||
Cli "github.com/docker/docker/cli"
|
Cli "github.com/docker/docker/cli"
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
flag "github.com/docker/docker/pkg/mflag"
|
||||||
|
"github.com/docker/docker/pkg/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
type copyDirection int
|
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
|
// client, a `:` could be part of an absolute Windows path, in which case it
|
||||||
// is immediately proceeded by a backslash.
|
// is immediately proceeded by a backslash.
|
||||||
func splitCpArg(arg string) (container, path string) {
|
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`.
|
// Explicit local absolute path, e.g., `C:\foo` or `/foo`.
|
||||||
return "", arg
|
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 the destination is a symbolic link, we should evaluate it.
|
||||||
if err == nil && dstStat.Mode&os.ModeSymlink != 0 {
|
if err == nil && dstStat.Mode&os.ModeSymlink != 0 {
|
||||||
linkTarget := dstStat.LinkTarget
|
linkTarget := dstStat.LinkTarget
|
||||||
if !filepath.IsAbs(linkTarget) {
|
if !system.IsAbs(linkTarget) {
|
||||||
// Join with the parent directory.
|
// Join with the parent directory.
|
||||||
dstParent, _ := archive.SplitPathDirEntry(dstPath)
|
dstParent, _ := archive.SplitPathDirEntry(dstPath)
|
||||||
linkTarget = filepath.Join(dstParent, linkTarget)
|
linkTarget = filepath.Join(dstParent, linkTarget)
|
||||||
|
|
|
@ -10,7 +10,7 @@ package builder
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -21,6 +21,7 @@ import (
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
flag "github.com/docker/docker/pkg/mflag"
|
||||||
"github.com/docker/docker/pkg/nat"
|
"github.com/docker/docker/pkg/nat"
|
||||||
"github.com/docker/docker/pkg/stringutils"
|
"github.com/docker/docker/pkg/stringutils"
|
||||||
|
"github.com/docker/docker/pkg/system"
|
||||||
"github.com/docker/docker/runconfig"
|
"github.com/docker/docker/runconfig"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -272,39 +273,15 @@ func workdir(b *builder, args []string, attributes map[string]bool, original str
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note that workdir passed comes from the Dockerfile. Hence it is in
|
// This is from the Dockerfile and will not necessarily be in platform
|
||||||
// Linux format using forward-slashes, even on Windows. However,
|
// specific semantics, hence ensure it is converted.
|
||||||
// b.Config.WorkingDir is in platform-specific notation (in other words
|
workdir := filepath.FromSlash(args[0])
|
||||||
// on Windows will use `\`
|
|
||||||
workdir := args[0]
|
|
||||||
|
|
||||||
isAbs := false
|
if !system.IsAbs(workdir) {
|
||||||
if runtime.GOOS == "windows" {
|
current := filepath.FromSlash(b.Config.WorkingDir)
|
||||||
// Alternate processing for Windows here is necessary as we can't call
|
workdir = filepath.Join(string(os.PathSeparator), current, workdir)
|
||||||
// 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 !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
|
b.Config.WorkingDir = workdir
|
||||||
|
|
||||||
return b.commit("", b.Config.Cmd, fmt.Sprintf("WORKDIR %v", 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
|
// Twiddle the destPath when its a relative path - meaning, make it
|
||||||
// relative to the WORKINGDIR
|
// relative to the WORKINGDIR
|
||||||
if !filepath.IsAbs(destPath) {
|
if !system.IsAbs(destPath) {
|
||||||
hasSlash := strings.HasSuffix(destPath, string(os.PathSeparator))
|
hasSlash := strings.HasSuffix(destPath, string(os.PathSeparator))
|
||||||
destPath = filepath.Join(string(os.PathSeparator), filepath.FromSlash(b.Config.WorkingDir), destPath)
|
destPath = filepath.Join(string(os.PathSeparator), filepath.FromSlash(b.Config.WorkingDir), destPath)
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
|
"github.com/docker/docker/pkg/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Errors used or returned by this file.
|
// Errors used or returned by this file.
|
||||||
|
@ -210,7 +211,7 @@ func CopyInfoDestinationPath(path string) (info CopyInfo, err error) {
|
||||||
return CopyInfo{}, err
|
return CopyInfo{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !filepath.IsAbs(linkTarget) {
|
if !system.IsAbs(linkTarget) {
|
||||||
// Join with the parent directory.
|
// Join with the parent directory.
|
||||||
dstParent, _ := SplitPathDirEntry(path)
|
dstParent, _ := SplitPathDirEntry(path)
|
||||||
linkTarget = filepath.Join(dstParent, linkTarget)
|
linkTarget = filepath.Join(dstParent, linkTarget)
|
||||||
|
|
|
@ -12,6 +12,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FollowSymlinkInScope is a wrapper around evalSymlinksInScope that returns an
|
// FollowSymlinkInScope is a wrapper around evalSymlinksInScope that returns an
|
||||||
|
@ -120,7 +122,7 @@ func evalSymlinksInScope(path, root string) (string, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if filepath.IsAbs(dest) {
|
if system.IsAbs(dest) {
|
||||||
b.Reset()
|
b.Reset()
|
||||||
}
|
}
|
||||||
path = dest + string(filepath.Separator) + path
|
path = dest + string(filepath.Separator) + path
|
||||||
|
|
Loading…
Add table
Reference in a new issue