mirror of https://github.com/docker/cli.git
command: change drive to lowercase for wsl path
On Windows, the drive casing doesn't matter outside of WSL. For WSL, the
drives are lowercase. When we're producing a WSL path, lowercase the
drive letter.
Co-authored-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
Co-authored-by: Laura Brehm <laurabrehm@hey.com>
Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
(cherry picked from commit 3472bbc28a
)
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
This commit is contained in:
parent
58a14cc379
commit
c6dde25470
|
@ -180,7 +180,7 @@ func toWslPath(s string) string {
|
||||||
if !ok {
|
if !ok {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("mnt/%s%s", drive, p)
|
return fmt.Sprintf("mnt/%s%s", strings.ToLower(drive), p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseUNCPath(s string) (drive, p string, ok bool) {
|
func parseUNCPath(s string) (drive, p string, ok bool) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/fs"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
"testing/fstest"
|
"testing/fstest"
|
||||||
|
@ -9,21 +10,48 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWslSocketPath(t *testing.T) {
|
func TestWslSocketPath(t *testing.T) {
|
||||||
u, err := url.Parse("unix:////./c:/my/file/path")
|
testCases := []struct {
|
||||||
assert.NilError(t, err)
|
doc string
|
||||||
|
fs fs.FS
|
||||||
|
url string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
doc: "filesystem where WSL path does not exist",
|
||||||
|
fs: fstest.MapFS{
|
||||||
|
"my/file/path": {},
|
||||||
|
},
|
||||||
|
url: "unix:////./c:/my/file/path",
|
||||||
|
expected: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
doc: "filesystem where WSL path exists",
|
||||||
|
fs: fstest.MapFS{
|
||||||
|
"mnt/c/my/file/path": {},
|
||||||
|
},
|
||||||
|
url: "unix:////./c:/my/file/path",
|
||||||
|
expected: "/mnt/c/my/file/path",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
doc: "filesystem where WSL path exists uppercase URL",
|
||||||
|
fs: fstest.MapFS{
|
||||||
|
"mnt/c/my/file/path": {},
|
||||||
|
},
|
||||||
|
url: "unix:////./C:/my/file/path",
|
||||||
|
expected: "/mnt/c/my/file/path",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
t.Run(tc.doc, func(t *testing.T) {
|
||||||
|
u, err := url.Parse(tc.url)
|
||||||
|
assert.NilError(t, err)
|
||||||
// Ensure host is empty.
|
// Ensure host is empty.
|
||||||
assert.Equal(t, u.Host, "")
|
assert.Equal(t, u.Host, "")
|
||||||
|
|
||||||
// Use a filesystem where the WSL path exists.
|
result := wslSocketPath(u.Path, tc.fs)
|
||||||
fs := fstest.MapFS{
|
|
||||||
"mnt/c/my/file/path": {},
|
|
||||||
}
|
|
||||||
assert.Equal(t, wslSocketPath(u.Path, fs), "/mnt/c/my/file/path")
|
|
||||||
|
|
||||||
// Use a filesystem where the WSL path doesn't exist.
|
assert.Equal(t, result, tc.expected)
|
||||||
fs = fstest.MapFS{
|
})
|
||||||
"my/file/path": {},
|
|
||||||
}
|
}
|
||||||
assert.Equal(t, wslSocketPath(u.Path, fs), "")
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue