Skip to content

Commit bc01f84

Browse files
authored
Merge pull request #6182 from thaJeztah/fork_longpath
remove use of github.com/docker/docker/pkg/longpath
2 parents ea2a0c3 + 53d02ec commit bc01f84

File tree

4 files changed

+46
-46
lines changed

4 files changed

+46
-46
lines changed

cli/command/image/build/context_windows.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,35 @@ package build
22

33
import (
44
"path/filepath"
5-
6-
"github.com/docker/docker/pkg/longpath"
5+
"strings"
76
)
87

98
func getContextRoot(srcPath string) (string, error) {
109
cr, err := filepath.Abs(srcPath)
1110
if err != nil {
1211
return "", err
1312
}
14-
return longpath.AddPrefix(cr), nil
13+
return addPrefix(cr), nil
14+
}
15+
16+
// longPathPrefix is the longpath prefix for Windows file paths.
17+
const longPathPrefix = `\\?\`
18+
19+
// addPrefix adds the Windows long path prefix to the path provided if
20+
// it does not already have it.
21+
//
22+
// See https://github.com/moby/moby/pull/15898
23+
//
24+
// This is a copy of [longpath.AddPrefix].
25+
//
26+
// [longpath.AddPrefix]:https://pkg.go.dev/github.com/docker/[email protected]+incompatible/pkg/longpath#AddPrefix
27+
func addPrefix(path string) string {
28+
if strings.HasPrefix(path, longPathPrefix) {
29+
return path
30+
}
31+
if strings.HasPrefix(path, `\\`) {
32+
// This is a UNC path, so we need to add 'UNC' to the path as well.
33+
return longPathPrefix + `UNC` + path[1:]
34+
}
35+
return longPathPrefix + path
1536
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package build
2+
3+
import (
4+
"strings"
5+
"testing"
6+
)
7+
8+
func TestStandardLongPath(t *testing.T) {
9+
c := `C:\simple\path`
10+
longC := addPrefix(c)
11+
if !strings.EqualFold(longC, `\\?\C:\simple\path`) {
12+
t.Errorf("Wrong long path returned. Original = %s ; Long = %s", c, longC)
13+
}
14+
}
15+
16+
func TestUNCLongPath(t *testing.T) {
17+
c := `\\server\share\path`
18+
longC := addPrefix(c)
19+
if !strings.EqualFold(longC, `\\?\UNC\server\share\path`) {
20+
t.Errorf("Wrong UNC long path returned. Original = %s ; Long = %s", c, longC)
21+
}
22+
}

vendor/github.com/docker/docker/pkg/longpath/longpath.go

Lines changed: 0 additions & 42 deletions
This file was deleted.

vendor/modules.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ github.com/docker/docker/internal/multierror
9797
github.com/docker/docker/pkg/homedir
9898
github.com/docker/docker/pkg/ioutils
9999
github.com/docker/docker/pkg/jsonmessage
100-
github.com/docker/docker/pkg/longpath
101100
github.com/docker/docker/pkg/process
102101
github.com/docker/docker/pkg/progress
103102
github.com/docker/docker/pkg/stdcopy

0 commit comments

Comments
 (0)