Merge pull request #15865 from Microsoft/10662-isabs

Windows: Fix use of IsAbs check
This commit is contained in:
Alexander Morozov 2015-08-26 13:29:24 -07:00
commit ebdb3bedd2
2 changed files with 24 additions and 0 deletions

View file

@ -4,6 +4,7 @@ package system
import (
"os"
"path/filepath"
)
// MkdirAll creates a directory named path along with any necessary parents,
@ -11,3 +12,8 @@ import (
func MkdirAll(path string, perm os.FileMode) error {
return os.MkdirAll(path, perm)
}
// IsAbs is a platform-specific wrapper for filepath.IsAbs.
func IsAbs(path string) bool {
return filepath.IsAbs(path)
}

View file

@ -4,7 +4,9 @@ package system
import (
"os"
"path/filepath"
"regexp"
"strings"
"syscall"
)
@ -62,3 +64,19 @@ func MkdirAll(path string, perm os.FileMode) error {
}
return nil
}
// IsAbs is a platform-specific 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 {
if !filepath.IsAbs(path) {
if !strings.HasPrefix(path, string(os.PathSeparator)) {
return false
}
}
return true
}