mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-10 13:37:08 +08:00
vendor: github.com/moby/buildkit v0.21.0-rc1
Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
This commit is contained in:
39
vendor/github.com/moby/buildkit/util/system/path.go
generated
vendored
39
vendor/github.com/moby/buildkit/util/system/path.go
generated
vendored
@ -2,7 +2,6 @@ package system
|
||||
|
||||
import (
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@ -46,7 +45,7 @@ func NormalizePath(parent, newPath, inputOS string, keepSlash bool) (string, err
|
||||
}
|
||||
|
||||
var err error
|
||||
parent, err = CheckSystemDriveAndRemoveDriveLetter(parent, inputOS)
|
||||
parent, err = CheckSystemDriveAndRemoveDriveLetter(parent, inputOS, keepSlash)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "removing drive letter")
|
||||
}
|
||||
@ -61,7 +60,7 @@ func NormalizePath(parent, newPath, inputOS string, keepSlash bool) (string, err
|
||||
newPath = parent
|
||||
}
|
||||
|
||||
newPath, err = CheckSystemDriveAndRemoveDriveLetter(newPath, inputOS)
|
||||
newPath, err = CheckSystemDriveAndRemoveDriveLetter(newPath, inputOS, keepSlash)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "removing drive letter")
|
||||
}
|
||||
@ -137,7 +136,7 @@ func IsAbs(pth, inputOS string) bool {
|
||||
if inputOS == "" {
|
||||
inputOS = "linux"
|
||||
}
|
||||
cleanedPath, err := CheckSystemDriveAndRemoveDriveLetter(pth, inputOS)
|
||||
cleanedPath, err := CheckSystemDriveAndRemoveDriveLetter(pth, inputOS, false)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
@ -174,7 +173,7 @@ func IsAbs(pth, inputOS string) bool {
|
||||
// There is no sane way to support this without adding a lot of complexity
|
||||
// which I am not sure is worth it.
|
||||
// \\.\C$\a --> Fail
|
||||
func CheckSystemDriveAndRemoveDriveLetter(path string, inputOS string) (string, error) {
|
||||
func CheckSystemDriveAndRemoveDriveLetter(path string, inputOS string, keepSlash bool) (string, error) {
|
||||
if inputOS == "" {
|
||||
inputOS = "linux"
|
||||
}
|
||||
@ -193,9 +192,10 @@ func CheckSystemDriveAndRemoveDriveLetter(path string, inputOS string) (string,
|
||||
}
|
||||
|
||||
parts := strings.SplitN(path, ":", 2)
|
||||
|
||||
// Path does not have a drive letter. Just return it.
|
||||
if len(parts) < 2 {
|
||||
return ToSlash(filepath.Clean(path), inputOS), nil
|
||||
return ToSlash(cleanPath(path, inputOS, keepSlash), inputOS), nil
|
||||
}
|
||||
|
||||
// We expect all paths to be in C:
|
||||
@ -220,5 +220,30 @@ func CheckSystemDriveAndRemoveDriveLetter(path string, inputOS string) (string,
|
||||
//
|
||||
// We must return the second element of the split path, as is, without attempting to convert
|
||||
// it to an absolute path. We have no knowledge of the CWD; that is treated elsewhere.
|
||||
return ToSlash(filepath.Clean(parts[1]), inputOS), nil
|
||||
return ToSlash(cleanPath(parts[1], inputOS, keepSlash), inputOS), nil
|
||||
}
|
||||
|
||||
// An adaptation of filepath.Clean to allow an option to
|
||||
// retain the trailing slash, on either of the platforms.
|
||||
// See https://github.com/moby/buildkit/issues/5249
|
||||
func cleanPath(origPath, inputOS string, keepSlash bool) string {
|
||||
// so as to handle cases like \\a\\b\\..\\c\\
|
||||
// on Linux, when inputOS is Windows
|
||||
origPath = ToSlash(origPath, inputOS)
|
||||
|
||||
if !keepSlash {
|
||||
return path.Clean(origPath)
|
||||
}
|
||||
|
||||
cleanedPath := path.Clean(origPath)
|
||||
// Windows supports both \\ and / as path separator.
|
||||
hasTrailingSlash := strings.HasSuffix(origPath, "/")
|
||||
if inputOS == "windows" {
|
||||
hasTrailingSlash = hasTrailingSlash || strings.HasSuffix(origPath, "\\")
|
||||
}
|
||||
|
||||
if len(cleanedPath) > 1 && hasTrailingSlash {
|
||||
return cleanedPath + "/"
|
||||
}
|
||||
return cleanedPath
|
||||
}
|
||||
|
17
vendor/github.com/moby/buildkit/util/system/path_unix.go
generated
vendored
Normal file
17
vendor/github.com/moby/buildkit/util/system/path_unix.go
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
//go:build !windows
|
||||
|
||||
package system
|
||||
|
||||
import "path/filepath"
|
||||
|
||||
// IsAbsolutePath is just a wrapper that calls filepath.IsAbs.
|
||||
// Has been added here just for symmetry with Windows.
|
||||
func IsAbsolutePath(path string) bool {
|
||||
return filepath.IsAbs(path)
|
||||
}
|
||||
|
||||
// GetAbsolutePath does nothing on non-Windows, just returns
|
||||
// the same path.
|
||||
func GetAbsolutePath(path string) string {
|
||||
return path
|
||||
}
|
29
vendor/github.com/moby/buildkit/util/system/path_windows.go
generated
vendored
Normal file
29
vendor/github.com/moby/buildkit/util/system/path_windows.go
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// DefaultSystemVolumeName is the default system volume label on Windows
|
||||
const DefaultSystemVolumeName = "C:"
|
||||
|
||||
// IsAbsolutePath prepends the default system volume label
|
||||
// to the path that is presumed absolute, and then calls filepath.IsAbs
|
||||
func IsAbsolutePath(path string) bool {
|
||||
path = filepath.Clean(path)
|
||||
if strings.HasPrefix(path, "\\") {
|
||||
path = DefaultSystemVolumeName + path
|
||||
}
|
||||
return filepath.IsAbs(path)
|
||||
}
|
||||
|
||||
// GetAbsolutePath returns an absolute path rooted
|
||||
// to C:\\ on Windows.
|
||||
func GetAbsolutePath(path string) string {
|
||||
path = filepath.Clean(path)
|
||||
if len(path) >= 2 && strings.EqualFold(path[:2], DefaultSystemVolumeName) {
|
||||
return path
|
||||
}
|
||||
return DefaultSystemVolumeName + path
|
||||
}
|
Reference in New Issue
Block a user