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:
Sebastiaan van Stijn 2022-10-08 00:08:42 +02:00
parent 9f3e5eead5
commit ad371893f2
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
5 changed files with 39 additions and 35 deletions

View file

@ -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)

View 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
}

View 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
}

View file

@ -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) {

View file

@ -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) {