Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions cli/command/image/build/context_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,35 @@ package build

import (
"path/filepath"

"github.com/docker/docker/pkg/longpath"
"strings"
)

func getContextRoot(srcPath string) (string, error) {
cr, err := filepath.Abs(srcPath)
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/[email protected]+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
}
22 changes: 22 additions & 0 deletions cli/command/image/build/context_windows_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
42 changes: 0 additions & 42 deletions vendor/github.com/docker/docker/pkg/longpath/longpath.go

This file was deleted.

1 change: 0 additions & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading