pkg/compose: use local copy of pkg/system.IsAbs

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2025-07-21 14:21:33 +02:00 committed by Guillaume Lours
parent d4f6000712
commit 1d2223fb23

View File

@ -31,7 +31,6 @@ import (
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/api"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/pkg/system"
"github.com/moby/go-archive" "github.com/moby/go-archive"
) )
@ -161,7 +160,7 @@ func (s *composeService) copyToContainer(ctx context.Context, containerID string
// 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 !system.IsAbs(linkTarget) { if !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)
@ -264,7 +263,7 @@ func (s *composeService) copyFromContainer(ctx context.Context, containerID, src
// If the destination is a symbolic link, we should follow it. // If the destination is a symbolic link, we should follow it.
if err == nil && srcStat.Mode&os.ModeSymlink != 0 { if err == nil && srcStat.Mode&os.ModeSymlink != 0 {
linkTarget := srcStat.LinkTarget linkTarget := srcStat.LinkTarget
if !system.IsAbs(linkTarget) { if !isAbs(linkTarget) {
// Join with the parent directory. // Join with the parent directory.
srcParent, _ := archive.SplitPathDirEntry(srcPath) srcParent, _ := archive.SplitPathDirEntry(srcPath)
linkTarget = filepath.Join(srcParent, linkTarget) linkTarget = filepath.Join(srcParent, linkTarget)
@ -302,8 +301,20 @@ func (s *composeService) copyFromContainer(ctx context.Context, containerID, src
return archive.CopyTo(preArchive, srcInfo, dstPath) return archive.CopyTo(preArchive, srcInfo, dstPath)
} }
// 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))
}
func splitCpArg(arg string) (ctr, path string) { func splitCpArg(arg string) (ctr, path string) {
if system.IsAbs(arg) { if 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
} }