mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #37770 from Microsoft/jjh/TestBuildSymlinkBreakout
Windows: Go1.11: Use long path in TestBuildSymlinkBreakout
This commit is contained in:
commit
7aa797fe92
3 changed files with 40 additions and 0 deletions
|
@ -24,6 +24,7 @@ import (
|
||||||
"github.com/docker/docker/internal/test/fakestorage"
|
"github.com/docker/docker/internal/test/fakestorage"
|
||||||
"github.com/docker/docker/internal/testutil"
|
"github.com/docker/docker/internal/testutil"
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
|
"github.com/docker/docker/pkg/system"
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
"github.com/moby/buildkit/frontend/dockerfile/command"
|
"github.com/moby/buildkit/frontend/dockerfile/command"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
|
@ -3601,6 +3602,11 @@ func (s *DockerSuite) TestBuildSymlinkBreakout(c *check.C) {
|
||||||
name := "testbuildsymlinkbreakout"
|
name := "testbuildsymlinkbreakout"
|
||||||
tmpdir, err := ioutil.TempDir("", name)
|
tmpdir, err := ioutil.TempDir("", name)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
|
// See https://github.com/moby/moby/pull/37770 for reason for next line.
|
||||||
|
tmpdir, err = system.GetLongPathName(tmpdir)
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
ctx := filepath.Join(tmpdir, "context")
|
ctx := filepath.Join(tmpdir, "context")
|
||||||
if err := os.MkdirAll(ctx, 0755); err != nil {
|
if err := os.MkdirAll(ctx, 0755); err != nil {
|
||||||
|
|
10
pkg/system/path_unix.go
Normal file
10
pkg/system/path_unix.go
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package system // import "github.com/docker/docker/pkg/system"
|
||||||
|
|
||||||
|
// GetLongPathName converts Windows short pathnames to full pathnames.
|
||||||
|
// For example C:\Users\ADMIN~1 --> C:\Users\Administrator.
|
||||||
|
// It is a no-op on non-Windows platforms
|
||||||
|
func GetLongPathName(path string) (string, error) {
|
||||||
|
return path, nil
|
||||||
|
}
|
24
pkg/system/path_windows.go
Normal file
24
pkg/system/path_windows.go
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package system // import "github.com/docker/docker/pkg/system"
|
||||||
|
|
||||||
|
import "syscall"
|
||||||
|
|
||||||
|
// GetLongPathName converts Windows short pathnames to full pathnames.
|
||||||
|
// For example C:\Users\ADMIN~1 --> C:\Users\Administrator.
|
||||||
|
// It is a no-op on non-Windows platforms
|
||||||
|
func GetLongPathName(path string) (string, error) {
|
||||||
|
// See https://groups.google.com/forum/#!topic/golang-dev/1tufzkruoTg
|
||||||
|
p := syscall.StringToUTF16(path)
|
||||||
|
b := p // GetLongPathName says we can reuse buffer
|
||||||
|
n, err := syscall.GetLongPathName(&p[0], &b[0], uint32(len(b)))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if n > uint32(len(b)) {
|
||||||
|
b = make([]uint16, n)
|
||||||
|
_, err = syscall.GetLongPathName(&p[0], &b[0], uint32(len(b)))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return syscall.UTF16ToString(b), nil
|
||||||
|
}
|
Loading…
Reference in a new issue