Skip to content

Commit

Permalink
[wsl] restore logic of WslPath.parseWindowsUncPath: both \\wsl$\
Browse files Browse the repository at this point in the history
…and `\\wsl.localhost\` paths should be supported regardless of Windows version (WEB-70562)

Regression after bcfeaa3bbf1d2e7f1aac349d46d0e0e73047ceed.
This also fixes `WslPathTest.parsing` test which was failing on Windows 10.

GitOrigin-RevId: dfcebc3174adeb7e37f493e140eaf2320981a4bf
  • Loading branch information
segrey authored and intellij-monorepo-bot committed Nov 28, 2024
1 parent 93a9754 commit ff3bd9f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,20 @@ static final class WSLToolFlags {
}

static @NotNull String getUncPrefix() {
return SystemInfo.isWin11OrNewer ? "\\\\wsl.localhost\\" : WslConstants.UNC_PREFIX;
return SystemInfo.isWin11OrNewer ? DEFAULT_UNC_PREFIX : WslConstants.UNC_PREFIX;
}

/**
* The default path prefix to access Linux files from Windows.
* This is a successor to the ` \\wsl$\` path prefix.
*
* <li>Windows 11</li>
* It's available since the initial release.
* <li>Windows 10</li>
* It's available since Windows 10 Insider Preview Build 21354.
* <a href="https://blogs.windows.com/windows-insider/2021/04/07/announcing-windows-10-insider-preview-build-21354/"></a>
* This preview was included in Windows 10 Version 21H2 (November 2021 Update).
*/
static final String DEFAULT_UNC_PREFIX = "\\\\wsl.localhost\\";
}
12 changes: 11 additions & 1 deletion platform/platform-impl/src/com/intellij/execution/wsl/WslPath.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,23 @@ data class WslPath internal constructor(private val prefix: String = WslConstant
fun toWindowsUncPath(): String = prefix + distributionId + toSystemDependentName(linuxPath)

companion object {

/**
* Parses a Windows UNC path and returns a `WslPath` object if successful.
* The path should start with `\\wsl.localhost\` or `\\wsl$\` prefix.
* Both prefixes are supported regardless of the preferred prefix on the particular Windows.
*
* @param windowsUncPath The Windows UNC path to be parsed.
* @return A `WslPath` object if the path is successfully parsed, or `null` otherwise.
* On OSes not supporting WSL, the method returns null.
*/
@JvmStatic
fun parseWindowsUncPath(windowsUncPath: String): WslPath? {
if (!WSLUtil.isSystemCompatible()) return null
val path = toSystemDependentName(windowsUncPath, '\\')

val legacyWslPrefix = WslConstants.UNC_PREFIX
val modernWslPrefix = WSLUtil.getUncPrefix()
val modernWslPrefix = WSLUtil.DEFAULT_UNC_PREFIX

return parseWindowsUncPath(path, legacyWslPrefix) ?: parseWindowsUncPath(path, modernWslPrefix)
}
Expand Down

0 comments on commit ff3bd9f

Please sign in to comment.