Signed-off-by: John Howard <jhoward@microsoft.com>
| ... | ... |
@@ -24,6 +24,7 @@ import ( |
| 24 | 24 |
"github.com/docker/docker/internal/test/fakestorage" |
| 25 | 25 |
"github.com/docker/docker/internal/testutil" |
| 26 | 26 |
"github.com/docker/docker/pkg/archive" |
| 27 |
+ "github.com/docker/docker/pkg/system" |
|
| 27 | 28 |
"github.com/go-check/check" |
| 28 | 29 |
"github.com/moby/buildkit/frontend/dockerfile/command" |
| 29 | 30 |
"github.com/opencontainers/go-digest" |
| ... | ... |
@@ -3601,6 +3602,11 @@ func (s *DockerSuite) TestBuildSymlinkBreakout(c *check.C) {
|
| 3601 | 3601 |
name := "testbuildsymlinkbreakout" |
| 3602 | 3602 |
tmpdir, err := ioutil.TempDir("", name)
|
| 3603 | 3603 |
c.Assert(err, check.IsNil) |
| 3604 |
+ |
|
| 3605 |
+ // See https://github.com/moby/moby/pull/37770 for reason for next line. |
|
| 3606 |
+ tmpdir, err = system.GetLongPathName(tmpdir) |
|
| 3607 |
+ c.Assert(err, check.IsNil) |
|
| 3608 |
+ |
|
| 3604 | 3609 |
defer os.RemoveAll(tmpdir) |
| 3605 | 3610 |
ctx := filepath.Join(tmpdir, "context") |
| 3606 | 3611 |
if err := os.MkdirAll(ctx, 0755); err != nil {
|
| 3607 | 3612 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,10 @@ |
| 0 |
+// +build !windows |
|
| 1 |
+ |
|
| 2 |
+package system // import "github.com/docker/docker/pkg/system" |
|
| 3 |
+ |
|
| 4 |
+// GetLongPathName converts Windows short pathnames to full pathnames. |
|
| 5 |
+// For example C:\Users\ADMIN~1 --> C:\Users\Administrator. |
|
| 6 |
+// It is a no-op on non-Windows platforms |
|
| 7 |
+func GetLongPathName(path string) (string, error) {
|
|
| 8 |
+ return path, nil |
|
| 9 |
+} |
| 0 | 10 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,24 @@ |
| 0 |
+package system // import "github.com/docker/docker/pkg/system" |
|
| 1 |
+ |
|
| 2 |
+import "syscall" |
|
| 3 |
+ |
|
| 4 |
+// GetLongPathName converts Windows short pathnames to full pathnames. |
|
| 5 |
+// For example C:\Users\ADMIN~1 --> C:\Users\Administrator. |
|
| 6 |
+// It is a no-op on non-Windows platforms |
|
| 7 |
+func GetLongPathName(path string) (string, error) {
|
|
| 8 |
+ // See https://groups.google.com/forum/#!topic/golang-dev/1tufzkruoTg |
|
| 9 |
+ p := syscall.StringToUTF16(path) |
|
| 10 |
+ b := p // GetLongPathName says we can reuse buffer |
|
| 11 |
+ n, err := syscall.GetLongPathName(&p[0], &b[0], uint32(len(b))) |
|
| 12 |
+ if err != nil {
|
|
| 13 |
+ return "", err |
|
| 14 |
+ } |
|
| 15 |
+ if n > uint32(len(b)) {
|
|
| 16 |
+ b = make([]uint16, n) |
|
| 17 |
+ _, err = syscall.GetLongPathName(&p[0], &b[0], uint32(len(b))) |
|
| 18 |
+ if err != nil {
|
|
| 19 |
+ return "", err |
|
| 20 |
+ } |
|
| 21 |
+ } |
|
| 22 |
+ return syscall.UTF16ToString(b), nil |
|
| 23 |
+} |