diff options
author | Brian Goff <cpuguy@hey.com> | 2022-08-29 13:57:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-29 13:57:51 -0700 |
commit | 5b9492a58ebf9a68f3e0b43b375c030486c26885 (patch) | |
tree | 3b8e829290d1631daa51795d716fa85ae78361d1 | |
parent | 1ac44105f995f8c6d94d296072d76e01ed7d6518 (diff) | |
parent | 2640aec0d78e4ba51e0d171cdcf79b14a38a6599 (diff) |
Merge pull request #44052 from thaJeztah/simplify_isabs
pkg/system: make IsAbs() platform-agnostic
-rw-r--r-- | pkg/system/filesys.go | 19 | ||||
-rw-r--r-- | pkg/system/filesys_unix.go | 10 | ||||
-rw-r--r-- | pkg/system/filesys_windows.go | 15 |
3 files changed, 20 insertions, 24 deletions
diff --git a/pkg/system/filesys.go b/pkg/system/filesys.go new file mode 100644 index 0000000000..ce5990c914 --- /dev/null +++ b/pkg/system/filesys.go @@ -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)) +} diff --git a/pkg/system/filesys_unix.go b/pkg/system/filesys_unix.go index 8b991201a9..61d5cd5b7b 100644 --- a/pkg/system/filesys_unix.go +++ b/pkg/system/filesys_unix.go @@ -3,10 +3,7 @@ package system // import "github.com/docker/docker/pkg/system" -import ( - "os" - "path/filepath" -) +import "os" // MkdirAllWithACL is a wrapper for os.MkdirAll on unix systems. 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) } -// 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. // They are passthrough on Unix platforms, and only relevant on Windows. diff --git a/pkg/system/filesys_windows.go b/pkg/system/filesys_windows.go index 8f79dc8fe0..00ba4728bb 100644 --- a/pkg/system/filesys_windows.go +++ b/pkg/system/filesys_windows.go @@ -5,7 +5,6 @@ import ( "path/filepath" "regexp" "strconv" - "strings" "sync" "syscall" "time" @@ -122,20 +121,6 @@ func mkdirWithACL(name string, sddl string) 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) || strings.HasPrefix(path, string(os.PathSeparator)) { - return true - } - return false -} - // 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 // specific use case. |