mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
build: resolve 8.3 filename format to long one on Windows
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
@ -70,7 +70,7 @@ func (c *Git) RootDir() (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return sanitizePath(root), nil
|
||||
return SanitizePath(root), nil
|
||||
}
|
||||
|
||||
func (c *Git) GitDir() (string, error) {
|
||||
|
@ -45,7 +45,7 @@ func gitPath(wd string) (string, error) {
|
||||
|
||||
var windowsPathRegex = regexp.MustCompile(`^[A-Za-z]:[\\/].*$`)
|
||||
|
||||
func sanitizePath(path string) string {
|
||||
func SanitizePath(path string) string {
|
||||
// If we're running in WSL, we need to convert Windows paths to Unix paths.
|
||||
// This is because the git binary can be invoked through `git.exe` and
|
||||
// therefore returns Windows paths.
|
@ -10,10 +10,10 @@ import (
|
||||
)
|
||||
|
||||
func TestSanitizePathUnix(t *testing.T) {
|
||||
assert.Equal(t, "/home/foobar", sanitizePath("/home/foobar"))
|
||||
assert.Equal(t, "/home/foobar", SanitizePath("/home/foobar"))
|
||||
}
|
||||
|
||||
func TestSanitizePathWSL(t *testing.T) {
|
||||
t.Setenv("WSL_DISTRO_NAME", "Ubuntu")
|
||||
assert.Equal(t, "/mnt/c/Users/foobar", sanitizePath("C:\\Users\\foobar"))
|
||||
assert.Equal(t, "/mnt/c/Users/foobar", SanitizePath("C:\\Users\\foobar"))
|
||||
}
|
||||
|
@ -9,6 +9,6 @@ func gitPath(wd string) (string, error) {
|
||||
return exec.LookPath("git.exe")
|
||||
}
|
||||
|
||||
func sanitizePath(path string) string {
|
||||
func SanitizePath(path string) string {
|
||||
return filepath.ToSlash(filepath.Clean(path))
|
||||
}
|
||||
|
@ -7,5 +7,5 @@ import (
|
||||
)
|
||||
|
||||
func TestSanitizePathWindows(t *testing.T) {
|
||||
assert.Equal(t, "C:\\Users\\foobar", sanitizePath("C:/Users/foobar"))
|
||||
assert.Equal(t, "C:\\Users\\foobar", SanitizePath("C:/Users/foobar"))
|
||||
}
|
||||
|
Reference in New Issue
Block a user