Skip to content

Commit a48c6e3

Browse files
committed
pkg/symlink: don't depend on pkg/system and pkg/longpath
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 6004b9a commit a48c6e3

3 files changed

Lines changed: 25 additions & 9 deletions

File tree

pkg/symlink/fs.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212
"os"
1313
"path/filepath"
1414
"strings"
15-
16-
"github.com/docker/docker/pkg/system"
1715
)
1816

1917
// FollowSymlinkInScope is a wrapper around evalSymlinksInScope that returns an
@@ -123,7 +121,7 @@ func evalSymlinksInScope(path, root string) (string, error) {
123121
if err != nil {
124122
return "", err
125123
}
126-
if system.IsAbs(dest) {
124+
if isAbs(dest) {
127125
b.Reset()
128126
}
129127
path = dest + string(filepath.Separator) + path

pkg/symlink/fs_unix.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ func evalSymlinks(path string) (string, error) {
1313
func isDriveOrRoot(p string) bool {
1414
return p == string(filepath.Separator)
1515
}
16+
17+
var isAbs = filepath.IsAbs

pkg/symlink/fs_windows.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"path/filepath"
88
"strings"
99

10-
"github.com/docker/docker/pkg/longpath"
1110
"golang.org/x/sys/windows"
1211
)
1312

@@ -77,7 +76,10 @@ func evalSymlinks(path string) (string, error) {
7776
return filepath.Clean(p), nil
7877
}
7978

80-
const utf8RuneSelf = 0x80
79+
const (
80+
utf8RuneSelf = 0x80
81+
longPathPrefix = `\\?\`
82+
)
8183

8284
func walkSymlinks(path string) (string, error) {
8385
const maxIter = 255
@@ -92,8 +94,8 @@ func walkSymlinks(path string) (string, error) {
9294

9395
// A path beginning with `\\?\` represents the root, so automatically
9496
// skip that part and begin processing the next segment.
95-
if strings.HasPrefix(path, longpath.Prefix) {
96-
b.WriteString(longpath.Prefix)
97+
if strings.HasPrefix(path, longPathPrefix) {
98+
b.WriteString(longPathPrefix)
9799
path = path[4:]
98100
continue
99101
}
@@ -123,7 +125,7 @@ func walkSymlinks(path string) (string, error) {
123125

124126
// If this is the first segment after the long path prefix, accept the
125127
// current segment as a volume root or UNC share and move on to the next.
126-
if b.String() == longpath.Prefix {
128+
if b.String() == longPathPrefix {
127129
b.WriteString(p)
128130
b.WriteRune(filepath.Separator)
129131
continue
@@ -146,7 +148,7 @@ func walkSymlinks(path string) (string, error) {
146148
if err != nil {
147149
return "", err
148150
}
149-
if filepath.IsAbs(dest) || os.IsPathSeparator(dest[0]) {
151+
if isAbs(dest) {
150152
b.Reset()
151153
}
152154
path = dest + string(filepath.Separator) + path
@@ -167,3 +169,17 @@ func isDriveOrRoot(p string) bool {
167169
}
168170
return false
169171
}
172+
173+
// isAbs is a platform-specific wrapper for filepath.IsAbs. On Windows,
174+
// golang filepath.IsAbs does not consider a path \windows\system32 as absolute
175+
// as it doesn't start with a drive-letter/colon combination. However, in
176+
// docker we need to verify things such as WORKDIR /windows/system32 in
177+
// a Dockerfile (which gets translated to \windows\system32 when being processed
178+
// by the daemon. This SHOULD be treated as absolute from a docker processing
179+
// perspective.
180+
func isAbs(path string) bool {
181+
if filepath.IsAbs(path) || strings.HasPrefix(path, string(os.PathSeparator)) {
182+
return true
183+
}
184+
return false
185+
}

0 commit comments

Comments
 (0)