pkg/system: move GetLongPathName to integration-cli
It's only used for an integration test, and has no external consumers. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
9f3e5eead5
commit
ad371893f2
5 changed files with 39 additions and 35 deletions
|
@ -19,7 +19,6 @@ import (
|
||||||
"github.com/docker/docker/integration-cli/cli"
|
"github.com/docker/docker/integration-cli/cli"
|
||||||
"github.com/docker/docker/integration-cli/cli/build"
|
"github.com/docker/docker/integration-cli/cli/build"
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
"github.com/docker/docker/pkg/system"
|
|
||||||
"github.com/docker/docker/testutil"
|
"github.com/docker/docker/testutil"
|
||||||
"github.com/docker/docker/testutil/fakecontext"
|
"github.com/docker/docker/testutil/fakecontext"
|
||||||
"github.com/docker/docker/testutil/fakegit"
|
"github.com/docker/docker/testutil/fakegit"
|
||||||
|
@ -3583,7 +3582,7 @@ func (s *DockerCLIBuildSuite) TestBuildSymlinkBreakout(c *testing.T) {
|
||||||
assert.NilError(c, err)
|
assert.NilError(c, err)
|
||||||
|
|
||||||
// See https://github.com/moby/moby/pull/37770 for reason for next line.
|
// See https://github.com/moby/moby/pull/37770 for reason for next line.
|
||||||
tmpdir, err = system.GetLongPathName(tmpdir)
|
tmpdir, err = getLongPathName(tmpdir)
|
||||||
assert.NilError(c, err)
|
assert.NilError(c, err)
|
||||||
|
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
11
integration-cli/utils_unix_test.go
Normal file
11
integration-cli/utils_unix_test.go
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
//go:build !windows
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
27
integration-cli/utils_windows_test.go
Normal file
27
integration-cli/utils_windows_test.go
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "golang.org/x/sys/windows"
|
||||||
|
|
||||||
|
// 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, 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
|
||||||
|
}
|
|
@ -3,13 +3,6 @@
|
||||||
|
|
||||||
package system // import "github.com/docker/docker/pkg/system"
|
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
|
|
||||||
}
|
|
||||||
|
|
||||||
// checkSystemDriveAndRemoveDriveLetter is the non-Windows implementation
|
// checkSystemDriveAndRemoveDriveLetter is the non-Windows implementation
|
||||||
// of CheckSystemDriveAndRemoveDriveLetter
|
// of CheckSystemDriveAndRemoveDriveLetter
|
||||||
func checkSystemDriveAndRemoveDriveLetter(path string) (string, error) {
|
func checkSystemDriveAndRemoveDriveLetter(path string) (string, error) {
|
||||||
|
|
|
@ -4,34 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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, 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
|
|
||||||
}
|
|
||||||
|
|
||||||
// checkSystemDriveAndRemoveDriveLetter is the Windows implementation
|
// checkSystemDriveAndRemoveDriveLetter is the Windows implementation
|
||||||
// of CheckSystemDriveAndRemoveDriveLetter
|
// of CheckSystemDriveAndRemoveDriveLetter
|
||||||
func checkSystemDriveAndRemoveDriveLetter(path string) (string, error) {
|
func checkSystemDriveAndRemoveDriveLetter(path string) (string, error) {
|
||||||
|
|
Loading…
Reference in a new issue