Skip to content

Commit c6dde25

Browse files
jsternberglaurazard
authored andcommitted
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 <[email protected]> Co-authored-by: Laura Brehm <[email protected]> Signed-off-by: Jonathan A. Sternberg <[email protected]> Signed-off-by: Laura Brehm <[email protected]> (cherry picked from commit 3472bbc) Signed-off-by: Laura Brehm <[email protected]>
1 parent 58a14cc commit c6dde25

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

cli/command/telemetry_docker.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func toWslPath(s string) string {
180180
if !ok {
181181
return ""
182182
}
183-
return fmt.Sprintf("mnt/%s%s", drive, p)
183+
return fmt.Sprintf("mnt/%s%s", strings.ToLower(drive), p)
184184
}
185185

186186
func parseUNCPath(s string) (drive, p string, ok bool) {

cli/command/telemetry_docker_test.go

+41-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package command
22

33
import (
4+
"io/fs"
45
"net/url"
56
"testing"
67
"testing/fstest"
@@ -9,21 +10,48 @@ import (
910
)
1011

1112
func TestWslSocketPath(t *testing.T) {
12-
u, err := url.Parse("unix:////./c:/my/file/path")
13-
assert.NilError(t, err)
13+
testCases := []struct {
14+
doc string
15+
fs fs.FS
16+
url string
17+
expected string
18+
}{
19+
{
20+
doc: "filesystem where WSL path does not exist",
21+
fs: fstest.MapFS{
22+
"my/file/path": {},
23+
},
24+
url: "unix:////./c:/my/file/path",
25+
expected: "",
26+
},
27+
{
28+
doc: "filesystem where WSL path exists",
29+
fs: fstest.MapFS{
30+
"mnt/c/my/file/path": {},
31+
},
32+
url: "unix:////./c:/my/file/path",
33+
expected: "/mnt/c/my/file/path",
34+
},
35+
{
36+
doc: "filesystem where WSL path exists uppercase URL",
37+
fs: fstest.MapFS{
38+
"mnt/c/my/file/path": {},
39+
},
40+
url: "unix:////./C:/my/file/path",
41+
expected: "/mnt/c/my/file/path",
42+
},
43+
}
1444

15-
// Ensure host is empty.
16-
assert.Equal(t, u.Host, "")
45+
for _, tc := range testCases {
46+
t.Run(tc.doc, func(t *testing.T) {
47+
u, err := url.Parse(tc.url)
48+
assert.NilError(t, err)
49+
// Ensure host is empty.
50+
assert.Equal(t, u.Host, "")
1751

18-
// Use a filesystem where the WSL path exists.
19-
fs := fstest.MapFS{
20-
"mnt/c/my/file/path": {},
21-
}
22-
assert.Equal(t, wslSocketPath(u.Path, fs), "/mnt/c/my/file/path")
52+
result := wslSocketPath(u.Path, tc.fs)
2353

24-
// Use a filesystem where the WSL path doesn't exist.
25-
fs = fstest.MapFS{
26-
"my/file/path": {},
54+
assert.Equal(t, result, tc.expected)
55+
})
2756
}
28-
assert.Equal(t, wslSocketPath(u.Path, fs), "")
2957
}

0 commit comments

Comments
 (0)