From ad371893f22ae7b13e34fb6630387347dd834eb3 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 8 Oct 2022 00:08:42 +0200 Subject: [PATCH] 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 --- integration-cli/docker_cli_build_test.go | 3 +-- integration-cli/utils_unix_test.go | 11 ++++++++++ integration-cli/utils_windows_test.go | 27 ++++++++++++++++++++++++ pkg/system/path_unix.go | 7 ------ pkg/system/path_windows.go | 26 ----------------------- 5 files changed, 39 insertions(+), 35 deletions(-) create mode 100644 integration-cli/utils_unix_test.go create mode 100644 integration-cli/utils_windows_test.go diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index ed04a99ce9..34969a5a7b 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -19,7 +19,6 @@ import ( "github.com/docker/docker/integration-cli/cli" "github.com/docker/docker/integration-cli/cli/build" "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/system" "github.com/docker/docker/testutil" "github.com/docker/docker/testutil/fakecontext" "github.com/docker/docker/testutil/fakegit" @@ -3583,7 +3582,7 @@ func (s *DockerCLIBuildSuite) TestBuildSymlinkBreakout(c *testing.T) { assert.NilError(c, err) // 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) defer os.RemoveAll(tmpdir) diff --git a/integration-cli/utils_unix_test.go b/integration-cli/utils_unix_test.go new file mode 100644 index 0000000000..abb7d2ff83 --- /dev/null +++ b/integration-cli/utils_unix_test.go @@ -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 +} diff --git a/integration-cli/utils_windows_test.go b/integration-cli/utils_windows_test.go new file mode 100644 index 0000000000..64eee19e6c --- /dev/null +++ b/integration-cli/utils_windows_test.go @@ -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 +} diff --git a/pkg/system/path_unix.go b/pkg/system/path_unix.go index 3778cf06d8..3976acf906 100644 --- a/pkg/system/path_unix.go +++ b/pkg/system/path_unix.go @@ -3,13 +3,6 @@ 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 // of CheckSystemDriveAndRemoveDriveLetter func checkSystemDriveAndRemoveDriveLetter(path string) (string, error) { diff --git a/pkg/system/path_windows.go b/pkg/system/path_windows.go index 708702ee1c..90a2430372 100644 --- a/pkg/system/path_windows.go +++ b/pkg/system/path_windows.go @@ -4,34 +4,8 @@ import ( "fmt" "path/filepath" "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 // of CheckSystemDriveAndRemoveDriveLetter func checkSystemDriveAndRemoveDriveLetter(path string) (string, error) {