wsl: better check for absolute Windows path, addon fix (IDEA-CR-34321)

This commit is contained in:
Sergey Simonchik
2018-06-29 15:52:08 +03:00
parent 615f5e45e2
commit 958e7b52ac
2 changed files with 7 additions and 0 deletions

View File

@@ -346,6 +346,12 @@ public class WSLDistribution {
@Nullable
public String getWslPath(@NotNull String windowsPath) {
if (FileUtil.isWindowsAbsolutePath(windowsPath)) { // absolute windows path => /mnt/disk_letter/path
if (windowsPath.length() > 2) {
char separator = windowsPath.charAt(2);
if (separator != '/' && separator != '\\') {
return null;
}
}
return WSL_MNT_ROOT +
Character.toLowerCase(windowsPath.charAt(0)) +
FileUtil.toSystemIndependentName(windowsPath.substring(2));

View File

@@ -55,6 +55,7 @@ public class WSLUtilTest {
assertWinPath("c:\\foo", "/mnt/c/foo");
assertWinPath("c:\\temp\\KeepCase", "/mnt/c/temp/KeepCase");
assertWinPath("?:\\temp\\KeepCase", null);
assertWinPath("c:c", null);
assertWinPath("%LOCALAPPDATA%\\lxss\\rootfs\\usr\\something\\include", "/usr/something/include");
assertWinPath("%LOCALAPPDATA%\\lxss\\rootfs\\usr\\something\\bin\\gcc", "/usr/something/bin/gcc");