From 1eda49878691e59dea88cc0cbab4ac0a11b7b6ca Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 16 Dec 2024 10:22:35 +0100 Subject: [PATCH] cli/command/container: use local copy of pkg/system.IsAbs Signed-off-by: Sebastiaan van Stijn --- cli/command/container/cp.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/cli/command/container/cp.go b/cli/command/container/cp.go index b361e2678cdc..d6fe10341a21 100644 --- a/cli/command/container/cp.go +++ b/cli/command/container/cp.go @@ -17,7 +17,6 @@ import ( "github.com/docker/cli/cli/streams" "github.com/docker/docker/api/types/container" "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/system" units "github.com/docker/go-units" "github.com/morikuni/aec" "github.com/pkg/errors" @@ -235,7 +234,7 @@ func copyFromContainer(ctx context.Context, dockerCli command.Cli, copyConfig cp // If the destination is a symbolic link, we should follow it. if err == nil && srcStat.Mode&os.ModeSymlink != 0 { linkTarget := srcStat.LinkTarget - if !system.IsAbs(linkTarget) { + if !isAbs(linkTarget) { // Join with the parent directory. srcParent, _ := archive.SplitPathDirEntry(srcPath) linkTarget = filepath.Join(srcParent, linkTarget) @@ -319,7 +318,7 @@ func copyToContainer(ctx context.Context, dockerCli command.Cli, copyConfig cpCo // If the destination is a symbolic link, we should evaluate it. if err == nil && dstStat.Mode&os.ModeSymlink != 0 { linkTarget := dstStat.LinkTarget - if !system.IsAbs(linkTarget) { + if !isAbs(linkTarget) { // Join with the parent directory. dstParent, _ := archive.SplitPathDirEntry(dstPath) linkTarget = filepath.Join(dstParent, linkTarget) @@ -434,7 +433,7 @@ func copyToContainer(ctx context.Context, dockerCli command.Cli, copyConfig cpCo // client, a `:` could be part of an absolute Windows path, in which case it // is immediately proceeded by a backslash. func splitCpArg(arg string) (ctr, path string) { - if system.IsAbs(arg) { + if isAbs(arg) { // Explicit local absolute path, e.g., `C:\foo` or `/foo`. return "", arg } @@ -448,3 +447,15 @@ func splitCpArg(arg string) (ctr, path string) { return ctr, path } + +// IsAbs is a platform-agnostic wrapper for filepath.IsAbs. +// +// On Windows, golang filepath.IsAbs does not consider a path \windows\system32 +// as absolute as it doesn't start with a drive-letter/colon combination. However, +// in docker we need to verify things such as WORKDIR /windows/system32 in +// a Dockerfile (which gets translated to \windows\system32 when being processed +// by the daemon). This SHOULD be treated as absolute from a docker processing +// perspective. +func isAbs(path string) bool { + return filepath.IsAbs(path) || strings.HasPrefix(path, string(os.PathSeparator)) +}