Skip to content

Commit

Permalink
Merge pull request moby#15865 from Microsoft/10662-isabs
Browse files Browse the repository at this point in the history
Windows: Fix use of IsAbs check
  • Loading branch information
LK4D4 committed Aug 26, 2015
2 parents fa13f7c + f11ba31 commit 47cdae2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ func (daemon *Daemon) verifyContainerSettings(hostConfig *runconfig.HostConfig,

// First perform verification of settings common across all platforms.
if config != nil {
if config.WorkingDir != "" && !filepath.IsAbs(config.WorkingDir) {
if config.WorkingDir != "" && !system.IsAbs(config.WorkingDir) {
return nil, fmt.Errorf("The working directory '%s' is invalid. It needs to be an absolute path.", config.WorkingDir)
}
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/system/filesys.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ package system

import (
"os"
"path/filepath"
)

// MkdirAll creates a directory named path along with any necessary parents,
// with permission specified by attribute perm for all dir created.
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)
}
18 changes: 18 additions & 0 deletions pkg/system/filesys_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ package system

import (
"os"
"path/filepath"
"regexp"
"strings"
"syscall"
)

Expand Down Expand Up @@ -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
}

0 comments on commit 47cdae2

Please sign in to comment.