Skip to content

Commit f8a2550

Browse files
committed
pkg/system: deprecate IsAbs and move internal
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 63bada4 commit f8a2550

5 files changed

Lines changed: 25 additions & 6 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
package dockerfile
22

3+
import (
4+
"os"
5+
"path/filepath"
6+
"strings"
7+
)
8+
39
func defaultShellForOS(os string) []string {
410
if os == "linux" {
511
return []string{"/bin/sh", "-c"}
612
}
713
return []string{"cmd", "/S", "/C"}
814
}
15+
16+
// isAbs is a platform-agnostic wrapper for filepath.IsAbs.
17+
//
18+
// On Windows, golang filepath.IsAbs does not consider a path \windows\system32
19+
// as absolute as it doesn't start with a drive-letter/colon combination. However,
20+
// in docker we need to verify things such as WORKDIR /windows/system32 in
21+
// a Dockerfile (which gets translated to \windows\system32 when being processed
22+
// by the daemon). This SHOULD be treated as absolute from a docker processing
23+
// perspective.
24+
func isAbs(path string) bool {
25+
return filepath.IsAbs(path) || strings.HasPrefix(path, string(os.PathSeparator))
26+
}

builder/dockerfile/copy_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ func normalizeDest(workingDir, requested string) (string, error) {
107107

108108
// Cannot handle relative where WorkingDir is not the system drive.
109109
if len(workingDir) > 0 {
110-
if ((len(workingDir) > 1) && !system.IsAbs(workingDir[2:])) || (len(workingDir) == 1) {
110+
if ((len(workingDir) > 1) && !isAbs(workingDir[2:])) || (len(workingDir) == 1) {
111111
return "", fmt.Errorf("Current WorkingDir %s is not platform consistent", workingDir)
112112
}
113-
if !system.IsAbs(dest) {
113+
if !isAbs(dest) {
114114
if string(workingDir[0]) != "C" {
115115
return "", fmt.Errorf("Windows does not support relative paths when WORKDIR is not the system drive")
116116
}

builder/dockerfile/dispatchers_windows.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"github.com/docker/docker/api/types/container"
1212
"github.com/docker/docker/internal/lazyregexp"
13-
"github.com/docker/docker/pkg/system"
1413
"github.com/moby/buildkit/frontend/dockerfile/instructions"
1514
)
1615

@@ -83,7 +82,7 @@ func normalizeWorkdirWindows(current string, requested string) (string, error) {
8382
// WORKDIR C:/foo \ WORKDIR bar --> C:\foo --> C:\foo\bar
8483
// WORKDIR C:/foo \ WORKDIR \\bar --> C:\foo --> C:\bar
8584
// WORKDIR /foo \ WORKDIR c:/bar --> C:\foo --> C:\bar
86-
if len(current) == 0 || system.IsAbs(requested) {
85+
if len(current) == 0 || isAbs(requested) {
8786
if (requested[0] == os.PathSeparator) ||
8887
(len(requested) > 1 && string(requested[1]) != ":") ||
8988
(len(requested) == 1) {

daemon/container.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"path/filepath"
88
"runtime"
9+
"strings"
910
"time"
1011

1112
"github.com/containerd/log"
@@ -19,7 +20,6 @@ import (
1920
"github.com/docker/docker/image"
2021
"github.com/docker/docker/oci/caps"
2122
"github.com/docker/docker/opts"
22-
"github.com/docker/docker/pkg/system"
2323
volumemounts "github.com/docker/docker/volume/mounts"
2424
"github.com/docker/go-connections/nat"
2525
"github.com/moby/sys/signal"
@@ -369,7 +369,7 @@ func translateWorkingDir(config *containertypes.Config) error {
369369
return nil
370370
}
371371
wd := filepath.FromSlash(config.WorkingDir) // Ensure in platform semantics
372-
if !system.IsAbs(wd) {
372+
if !filepath.IsAbs(wd) && !strings.HasPrefix(wd, string(os.PathSeparator)) {
373373
return fmt.Errorf("the working directory '%s' is invalid, it needs to be an absolute path", config.WorkingDir)
374374
}
375375
config.WorkingDir = filepath.Clean(wd)

pkg/system/filesys.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
// a Dockerfile (which gets translated to \windows\system32 when being processed
1515
// by the daemon). This SHOULD be treated as absolute from a docker processing
1616
// perspective.
17+
//
18+
// Deprecated: this function was only used internally and will be removed in the next release.
1719
func IsAbs(path string) bool {
1820
return filepath.IsAbs(path) || strings.HasPrefix(path, string(os.PathSeparator))
1921
}

0 commit comments

Comments
 (0)