Skip to content

Commit d3b59fb

Browse files
committed
cli/command/container: use local copy of pkg/system.IsAbs
Signed-off-by: Sebastiaan van Stijn <[email protected]> (cherry picked from commit 1eda498) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent ac40240 commit d3b59fb

File tree

1 file changed

+15
-4
lines changed
  • cli/command/container

1 file changed

+15
-4
lines changed

cli/command/container/cp.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"github.com/docker/cli/cli/streams"
1818
"github.com/docker/docker/api/types/container"
1919
"github.com/docker/docker/pkg/archive"
20-
"github.com/docker/docker/pkg/system"
2120
units "github.com/docker/go-units"
2221
"github.com/morikuni/aec"
2322
"github.com/pkg/errors"
@@ -235,7 +234,7 @@ func copyFromContainer(ctx context.Context, dockerCli command.Cli, copyConfig cp
235234
// If the destination is a symbolic link, we should follow it.
236235
if err == nil && srcStat.Mode&os.ModeSymlink != 0 {
237236
linkTarget := srcStat.LinkTarget
238-
if !system.IsAbs(linkTarget) {
237+
if !isAbs(linkTarget) {
239238
// Join with the parent directory.
240239
srcParent, _ := archive.SplitPathDirEntry(srcPath)
241240
linkTarget = filepath.Join(srcParent, linkTarget)
@@ -319,7 +318,7 @@ func copyToContainer(ctx context.Context, dockerCli command.Cli, copyConfig cpCo
319318
// If the destination is a symbolic link, we should evaluate it.
320319
if err == nil && dstStat.Mode&os.ModeSymlink != 0 {
321320
linkTarget := dstStat.LinkTarget
322-
if !system.IsAbs(linkTarget) {
321+
if !isAbs(linkTarget) {
323322
// Join with the parent directory.
324323
dstParent, _ := archive.SplitPathDirEntry(dstPath)
325324
linkTarget = filepath.Join(dstParent, linkTarget)
@@ -434,7 +433,7 @@ func copyToContainer(ctx context.Context, dockerCli command.Cli, copyConfig cpCo
434433
// client, a `:` could be part of an absolute Windows path, in which case it
435434
// is immediately proceeded by a backslash.
436435
func splitCpArg(arg string) (ctr, path string) {
437-
if system.IsAbs(arg) {
436+
if isAbs(arg) {
438437
// Explicit local absolute path, e.g., `C:\foo` or `/foo`.
439438
return "", arg
440439
}
@@ -448,3 +447,15 @@ func splitCpArg(arg string) (ctr, path string) {
448447

449448
return ctr, path
450449
}
450+
451+
// IsAbs is a platform-agnostic wrapper for filepath.IsAbs.
452+
//
453+
// On Windows, golang filepath.IsAbs does not consider a path \windows\system32
454+
// as absolute as it doesn't start with a drive-letter/colon combination. However,
455+
// in docker we need to verify things such as WORKDIR /windows/system32 in
456+
// a Dockerfile (which gets translated to \windows\system32 when being processed
457+
// by the daemon). This SHOULD be treated as absolute from a docker processing
458+
// perspective.
459+
func isAbs(path string) bool {
460+
return filepath.IsAbs(path) || strings.HasPrefix(path, string(os.PathSeparator))
461+
}

0 commit comments

Comments
 (0)