mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
pkg/system: make IsAbs() platform-agnostic
filepath.IsAbs() will short-circuit on Linux/Unix, so having a single
implementation should not affect those platforms.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 2640aec0d7
)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
d2590dc3cd
commit
40515da6d6
3 changed files with 20 additions and 24 deletions
19
pkg/system/filesys.go
Normal file
19
pkg/system/filesys.go
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
package system
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IsAbs is a platform-agnostic 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 {
|
||||||
|
return filepath.IsAbs(path) || strings.HasPrefix(path, string(os.PathSeparator))
|
||||||
|
}
|
|
@ -3,10 +3,7 @@
|
||||||
|
|
||||||
package system // import "github.com/docker/docker/pkg/system"
|
package system // import "github.com/docker/docker/pkg/system"
|
||||||
|
|
||||||
import (
|
import "os"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
|
||||||
|
|
||||||
// MkdirAllWithACL is a wrapper for os.MkdirAll on unix systems.
|
// MkdirAllWithACL is a wrapper for os.MkdirAll on unix systems.
|
||||||
func MkdirAllWithACL(path string, perm os.FileMode, sddl string) error {
|
func MkdirAllWithACL(path string, perm os.FileMode, sddl string) error {
|
||||||
|
@ -19,11 +16,6 @@ func MkdirAll(path string, perm os.FileMode) error {
|
||||||
return os.MkdirAll(path, perm)
|
return os.MkdirAll(path, perm)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsAbs is a platform-specific wrapper for filepath.IsAbs.
|
|
||||||
func IsAbs(path string) bool {
|
|
||||||
return filepath.IsAbs(path)
|
|
||||||
}
|
|
||||||
|
|
||||||
// The functions below here are wrappers for the equivalents in the os and ioutils packages.
|
// The functions below here are wrappers for the equivalents in the os and ioutils packages.
|
||||||
// They are passthrough on Unix platforms, and only relevant on Windows.
|
// They are passthrough on Unix platforms, and only relevant on Windows.
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
@ -122,20 +121,6 @@ func mkdirWithACL(name string, sddl string) error {
|
||||||
return nil
|
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) || strings.HasPrefix(path, string(os.PathSeparator)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// The origin of the functions below here are the golang OS and windows packages,
|
// The origin of the functions below here are the golang OS and windows packages,
|
||||||
// slightly modified to only cope with files, not directories due to the
|
// slightly modified to only cope with files, not directories due to the
|
||||||
// specific use case.
|
// specific use case.
|
||||||
|
|
Loading…
Reference in a new issue