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:
19
build/git.go
19
build/git.go
@ -46,9 +46,9 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st
|
||||
if filepath.IsAbs(contextPath) {
|
||||
wd = contextPath
|
||||
} else {
|
||||
cwd, _ := os.Getwd()
|
||||
wd, _ = filepath.Abs(filepath.Join(cwd, contextPath))
|
||||
wd, _ = filepath.Abs(filepath.Join(getWd(), contextPath))
|
||||
}
|
||||
wd = gitutil.SanitizePath(wd)
|
||||
|
||||
gitc, err := gitutil.New(gitutil.WithContext(ctx), gitutil.WithWorkingDir(wd))
|
||||
if err != nil {
|
||||
@ -104,8 +104,7 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st
|
||||
dockerfilePath = filepath.Join(wd, "Dockerfile")
|
||||
}
|
||||
if !filepath.IsAbs(dockerfilePath) {
|
||||
cwd, _ := os.Getwd()
|
||||
dockerfilePath = filepath.Join(cwd, dockerfilePath)
|
||||
dockerfilePath = filepath.Join(getWd(), dockerfilePath)
|
||||
}
|
||||
if r, err := filepath.Rel(root, dockerfilePath); err == nil && !strings.HasPrefix(r, "..") {
|
||||
res["label:"+DockerfileLabel] = r
|
||||
@ -125,9 +124,21 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if lp, err := getLongPathName(dir); err == nil {
|
||||
dir = lp
|
||||
}
|
||||
dir = gitutil.SanitizePath(dir)
|
||||
if r, err := filepath.Rel(root, dir); err == nil && !strings.HasPrefix(r, "..") {
|
||||
so.FrontendAttrs["vcs:localdir:"+k] = r
|
||||
}
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getWd() string {
|
||||
wd, _ := os.Getwd()
|
||||
if lp, err := getLongPathName(wd); err == nil {
|
||||
return lp
|
||||
}
|
||||
return wd
|
||||
}
|
||||
|
9
build/git_unix.go
Normal file
9
build/git_unix.go
Normal file
@ -0,0 +1,9 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package build
|
||||
|
||||
// getLongPathName is a no-op on non-Windows platforms.
|
||||
func getLongPathName(path string) (string, error) {
|
||||
return path, nil
|
||||
}
|
26
build/git_windows.go
Normal file
26
build/git_windows.go
Normal file
@ -0,0 +1,26 @@
|
||||
package build
|
||||
|
||||
import "golang.org/x/sys/windows"
|
||||
|
||||
// getLongPathName converts Windows short pathnames to full pathnames.
|
||||
// For example C:\Users\ADMIN~1 --> C:\Users\Administrator.
|
||||
func getLongPathName(path string) (string, error) {
|
||||
// See https://groups.google.com/forum/#!topic/golang-dev/1tufzkruoTg
|
||||
p, err := windows.UTF16FromString(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
b := p // GetLongPathName says we can reuse buffer
|
||||
n, err := windows.GetLongPathName(&p[0], &b[0], uint32(len(b)))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if n > uint32(len(b)) {
|
||||
b = make([]uint16, n)
|
||||
_, err = windows.GetLongPathName(&p[0], &b[0], uint32(len(b)))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
return windows.UTF16ToString(b), nil
|
||||
}
|
Reference in New Issue
Block a user