Signed-off-by: John Howard <jhoward@microsoft.com>
| ... | ... |
@@ -15,6 +15,7 @@ import ( |
| 15 | 15 |
Cli "github.com/docker/docker/cli" |
| 16 | 16 |
"github.com/docker/docker/pkg/archive" |
| 17 | 17 |
flag "github.com/docker/docker/pkg/mflag" |
| 18 |
+ "github.com/docker/docker/pkg/system" |
|
| 18 | 19 |
) |
| 19 | 20 |
|
| 20 | 21 |
type copyDirection int |
| ... | ... |
@@ -101,7 +102,7 @@ func (cli *DockerCli) CmdCp(args ...string) error {
|
| 101 | 101 |
// client, a `:` could be part of an absolute Windows path, in which case it |
| 102 | 102 |
// is immediately proceeded by a backslash. |
| 103 | 103 |
func splitCpArg(arg string) (container, path string) {
|
| 104 |
- if filepath.IsAbs(arg) {
|
|
| 104 |
+ if system.IsAbs(arg) {
|
|
| 105 | 105 |
// Explicit local absolute path, e.g., `C:\foo` or `/foo`. |
| 106 | 106 |
return "", arg |
| 107 | 107 |
} |
| ... | ... |
@@ -236,7 +237,7 @@ func (cli *DockerCli) copyToContainer(srcPath, dstContainer, dstPath string) (er |
| 236 | 236 |
// If the destination is a symbolic link, we should evaluate it. |
| 237 | 237 |
if err == nil && dstStat.Mode&os.ModeSymlink != 0 {
|
| 238 | 238 |
linkTarget := dstStat.LinkTarget |
| 239 |
- if !filepath.IsAbs(linkTarget) {
|
|
| 239 |
+ if !system.IsAbs(linkTarget) {
|
|
| 240 | 240 |
// Join with the parent directory. |
| 241 | 241 |
dstParent, _ := archive.SplitPathDirEntry(dstPath) |
| 242 | 242 |
linkTarget = filepath.Join(dstParent, linkTarget) |
| ... | ... |
@@ -10,7 +10,7 @@ package builder |
| 10 | 10 |
import ( |
| 11 | 11 |
"fmt" |
| 12 | 12 |
"io/ioutil" |
| 13 |
- "path" |
|
| 13 |
+ "os" |
|
| 14 | 14 |
"path/filepath" |
| 15 | 15 |
"regexp" |
| 16 | 16 |
"runtime" |
| ... | ... |
@@ -21,6 +21,7 @@ import ( |
| 21 | 21 |
flag "github.com/docker/docker/pkg/mflag" |
| 22 | 22 |
"github.com/docker/docker/pkg/nat" |
| 23 | 23 |
"github.com/docker/docker/pkg/stringutils" |
| 24 |
+ "github.com/docker/docker/pkg/system" |
|
| 24 | 25 |
"github.com/docker/docker/runconfig" |
| 25 | 26 |
) |
| 26 | 27 |
|
| ... | ... |
@@ -272,39 +273,15 @@ func workdir(b *builder, args []string, attributes map[string]bool, original str |
| 272 | 272 |
return err |
| 273 | 273 |
} |
| 274 | 274 |
|
| 275 |
- // Note that workdir passed comes from the Dockerfile. Hence it is in |
|
| 276 |
- // Linux format using forward-slashes, even on Windows. However, |
|
| 277 |
- // b.Config.WorkingDir is in platform-specific notation (in other words |
|
| 278 |
- // on Windows will use `\` |
|
| 279 |
- workdir := args[0] |
|
| 275 |
+ // This is from the Dockerfile and will not necessarily be in platform |
|
| 276 |
+ // specific semantics, hence ensure it is converted. |
|
| 277 |
+ workdir := filepath.FromSlash(args[0]) |
|
| 280 | 278 |
|
| 281 |
- isAbs := false |
|
| 282 |
- if runtime.GOOS == "windows" {
|
|
| 283 |
- // Alternate processing for Windows here is necessary as we can't call |
|
| 284 |
- // filepath.IsAbs(workDir) as that would verify Windows style paths, |
|
| 285 |
- // along with drive-letters (eg c:\pathto\file.txt). We (arguably |
|
| 286 |
- // correctly or not) check for both forward and back slashes as this |
|
| 287 |
- // is what the 1.4.2 GoLang implementation of IsAbs() does in the |
|
| 288 |
- // isSlash() function. |
|
| 289 |
- isAbs = workdir[0] == '\\' || workdir[0] == '/' |
|
| 290 |
- } else {
|
|
| 291 |
- isAbs = filepath.IsAbs(workdir) |
|
| 292 |
- } |
|
| 293 |
- |
|
| 294 |
- if !isAbs {
|
|
| 295 |
- current := b.Config.WorkingDir |
|
| 296 |
- if runtime.GOOS == "windows" {
|
|
| 297 |
- // Convert to Linux format before join |
|
| 298 |
- current = strings.Replace(current, "\\", "/", -1) |
|
| 299 |
- } |
|
| 300 |
- // Must use path.Join so works correctly on Windows, not filepath |
|
| 301 |
- workdir = path.Join("/", current, workdir)
|
|
| 279 |
+ if !system.IsAbs(workdir) {
|
|
| 280 |
+ current := filepath.FromSlash(b.Config.WorkingDir) |
|
| 281 |
+ workdir = filepath.Join(string(os.PathSeparator), current, workdir) |
|
| 302 | 282 |
} |
| 303 | 283 |
|
| 304 |
- // Convert to platform specific format |
|
| 305 |
- if runtime.GOOS == "windows" {
|
|
| 306 |
- workdir = strings.Replace(workdir, "/", "\\", -1) |
|
| 307 |
- } |
|
| 308 | 284 |
b.Config.WorkingDir = workdir |
| 309 | 285 |
|
| 310 | 286 |
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 |
| 270 | 270 |
|
| 271 | 271 |
// Twiddle the destPath when its a relative path - meaning, make it |
| 272 | 272 |
// relative to the WORKINGDIR |
| 273 |
- if !filepath.IsAbs(destPath) {
|
|
| 273 |
+ if !system.IsAbs(destPath) {
|
|
| 274 | 274 |
hasSlash := strings.HasSuffix(destPath, string(os.PathSeparator)) |
| 275 | 275 |
destPath = filepath.Join(string(os.PathSeparator), filepath.FromSlash(b.Config.WorkingDir), destPath) |
| 276 | 276 |
|
| ... | ... |
@@ -10,6 +10,7 @@ import ( |
| 10 | 10 |
"strings" |
| 11 | 11 |
|
| 12 | 12 |
"github.com/Sirupsen/logrus" |
| 13 |
+ "github.com/docker/docker/pkg/system" |
|
| 13 | 14 |
) |
| 14 | 15 |
|
| 15 | 16 |
// Errors used or returned by this file. |
| ... | ... |
@@ -210,7 +211,7 @@ func CopyInfoDestinationPath(path string) (info CopyInfo, err error) {
|
| 210 | 210 |
return CopyInfo{}, err
|
| 211 | 211 |
} |
| 212 | 212 |
|
| 213 |
- if !filepath.IsAbs(linkTarget) {
|
|
| 213 |
+ if !system.IsAbs(linkTarget) {
|
|
| 214 | 214 |
// Join with the parent directory. |
| 215 | 215 |
dstParent, _ := SplitPathDirEntry(path) |
| 216 | 216 |
linkTarget = filepath.Join(dstParent, linkTarget) |
| ... | ... |
@@ -12,6 +12,8 @@ import ( |
| 12 | 12 |
"os" |
| 13 | 13 |
"path/filepath" |
| 14 | 14 |
"strings" |
| 15 |
+ |
|
| 16 |
+ "github.com/docker/docker/pkg/system" |
|
| 15 | 17 |
) |
| 16 | 18 |
|
| 17 | 19 |
// FollowSymlinkInScope is a wrapper around evalSymlinksInScope that returns an |
| ... | ... |
@@ -120,7 +122,7 @@ func evalSymlinksInScope(path, root string) (string, error) {
|
| 120 | 120 |
if err != nil {
|
| 121 | 121 |
return "", err |
| 122 | 122 |
} |
| 123 |
- if filepath.IsAbs(dest) {
|
|
| 123 |
+ if system.IsAbs(dest) {
|
|
| 124 | 124 |
b.Reset() |
| 125 | 125 |
} |
| 126 | 126 |
path = dest + string(filepath.Separator) + path |