mirror of https://github.com/docker/cli.git
Merge pull request #6182 from thaJeztah/fork_longpath
remove use of github.com/docker/docker/pkg/longpath
This commit is contained in:
commit
bc01f8489d
|
|
@ -2,8 +2,7 @@ package build
|
|||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/docker/docker/pkg/longpath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func getContextRoot(srcPath string) (string, error) {
|
||||
|
|
@ -11,5 +10,27 @@ func getContextRoot(srcPath string) (string, error) {
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return longpath.AddPrefix(cr), nil
|
||||
return addPrefix(cr), nil
|
||||
}
|
||||
|
||||
// longPathPrefix is the longpath prefix for Windows file paths.
|
||||
const longPathPrefix = `\\?\`
|
||||
|
||||
// addPrefix adds the Windows long path prefix to the path provided if
|
||||
// it does not already have it.
|
||||
//
|
||||
// See https://github.com/moby/moby/pull/15898
|
||||
//
|
||||
// This is a copy of [longpath.AddPrefix].
|
||||
//
|
||||
// [longpath.AddPrefix]:https://pkg.go.dev/github.com/docker/docker@v28.3.2+incompatible/pkg/longpath#AddPrefix
|
||||
func addPrefix(path string) string {
|
||||
if strings.HasPrefix(path, longPathPrefix) {
|
||||
return path
|
||||
}
|
||||
if strings.HasPrefix(path, `\\`) {
|
||||
// This is a UNC path, so we need to add 'UNC' to the path as well.
|
||||
return longPathPrefix + `UNC` + path[1:]
|
||||
}
|
||||
return longPathPrefix + path
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
package build
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStandardLongPath(t *testing.T) {
|
||||
c := `C:\simple\path`
|
||||
longC := addPrefix(c)
|
||||
if !strings.EqualFold(longC, `\\?\C:\simple\path`) {
|
||||
t.Errorf("Wrong long path returned. Original = %s ; Long = %s", c, longC)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUNCLongPath(t *testing.T) {
|
||||
c := `\\server\share\path`
|
||||
longC := addPrefix(c)
|
||||
if !strings.EqualFold(longC, `\\?\UNC\server\share\path`) {
|
||||
t.Errorf("Wrong UNC long path returned. Original = %s ; Long = %s", c, longC)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
// Package longpath introduces some constants and helper functions for handling
|
||||
// long paths in Windows.
|
||||
//
|
||||
// Long paths are expected to be prepended with "\\?\" and followed by either a
|
||||
// drive letter, a UNC server\share, or a volume identifier.
|
||||
package longpath
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// longPathPrefix is the longpath prefix for Windows file paths.
|
||||
const longPathPrefix = `\\?\`
|
||||
|
||||
// AddPrefix adds the Windows long path prefix to the path provided if
|
||||
// it does not already have it.
|
||||
func AddPrefix(path string) string {
|
||||
if strings.HasPrefix(path, longPathPrefix) {
|
||||
return path
|
||||
}
|
||||
if strings.HasPrefix(path, `\\`) {
|
||||
// This is a UNC path, so we need to add 'UNC' to the path as well.
|
||||
return longPathPrefix + `UNC` + path[1:]
|
||||
}
|
||||
return longPathPrefix + path
|
||||
}
|
||||
|
||||
// MkdirTemp is the equivalent of [os.MkdirTemp], except that on Windows
|
||||
// the result is in Windows longpath format. On Unix systems it is
|
||||
// equivalent to [os.MkdirTemp].
|
||||
func MkdirTemp(dir, prefix string) (string, error) {
|
||||
tempDir, err := os.MkdirTemp(dir, prefix)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if runtime.GOOS != "windows" {
|
||||
return tempDir, nil
|
||||
}
|
||||
return AddPrefix(tempDir), nil
|
||||
}
|
||||
|
|
@ -97,7 +97,6 @@ github.com/docker/docker/internal/multierror
|
|||
github.com/docker/docker/pkg/homedir
|
||||
github.com/docker/docker/pkg/ioutils
|
||||
github.com/docker/docker/pkg/jsonmessage
|
||||
github.com/docker/docker/pkg/longpath
|
||||
github.com/docker/docker/pkg/process
|
||||
github.com/docker/docker/pkg/progress
|
||||
github.com/docker/docker/pkg/stdcopy
|
||||
|
|
|
|||
Loading…
Reference in New Issue