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
8284func 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