mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-14 18:05:27 +07:00
[wsl][maven][IDEA-371398][IJ-CR-161241] do not use the maven distribution leaked from the Window %PATH% environment variable
(cherry picked from commit f5a1e71920676b6f048b4a91d1ad52ecf4ac4fe7) GitOrigin-RevId: 85263f3886f12ba42a0ddf64c38126b1b227e303
This commit is contained in:
committed by
intellij-monorepo-bot
parent
93d1dfe183
commit
5d3ac87849
@@ -91,6 +91,23 @@ object EelPathUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/** If [path] is `\\wsl.localhost\Ubuntu\mnt\c\Program Files`, then actual path is `C:\Program Files` */
|
||||
@JvmStatic
|
||||
fun getActualPath(path: Path): Path = path.run {
|
||||
if (
|
||||
isAbsolute &&
|
||||
nameCount >= 2 &&
|
||||
getName(0).toString() == "mnt" &&
|
||||
getName(1).toString().run { length == 1 && first().isLetter() }
|
||||
)
|
||||
asSequence()
|
||||
.drop(2)
|
||||
.map(Path::toString)
|
||||
.fold(fileSystem.getPath("${getName(1).toString().uppercase()}:\\"), Path::resolve)
|
||||
else
|
||||
this
|
||||
}
|
||||
|
||||
/**
|
||||
* ```kotlin
|
||||
* getUriLocalToEel(Path.of("\\\\wsl.localhost\\Ubuntu\\home\\user\\dir")).toString() = "file:/home/user/dir"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package com.intellij.execution.wsl.ijent.nio
|
||||
|
||||
import com.intellij.platform.core.nio.fs.BasicFileAttributesHolder2
|
||||
import com.intellij.platform.eel.provider.utils.EelPathUtils.getActualPath
|
||||
import java.net.URI
|
||||
import java.nio.file.*
|
||||
|
||||
@@ -19,21 +20,7 @@ class IjentWslNioPath(
|
||||
require(presentablePath !is IjentWslNioPath) { "IjentWslNioPath should be a wrapper over other instances of path, namely WindowsPath or IjentNioPath" }
|
||||
}
|
||||
|
||||
/** If [presentablePath] is `\\wsl.localhost\Ubuntu\mnt\c\Program Files`, then [actualPath] is `C:\Program Files` */
|
||||
val actualPath: Path = presentablePath.run {
|
||||
if (
|
||||
isAbsolute &&
|
||||
nameCount >= 2 &&
|
||||
getName(0).toString() == "mnt" &&
|
||||
getName(1).toString().run { length == 1 && first().isLetter() }
|
||||
)
|
||||
asSequence()
|
||||
.drop(2)
|
||||
.map(Path::toString)
|
||||
.fold(fileSystem.getPath("${getName(1).toString().uppercase()}:\\"), Path::resolve)
|
||||
else
|
||||
this
|
||||
}
|
||||
val actualPath: Path = getActualPath(presentablePath)
|
||||
|
||||
override fun getFileSystem(): IjentWslNioFileSystem = fileSystem
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.intellij.platform.eel.fs.getPath
|
||||
import com.intellij.platform.eel.provider.asNioPath
|
||||
import com.intellij.platform.eel.provider.asNioPathOrNull
|
||||
import com.intellij.platform.eel.provider.getEelDescriptor
|
||||
import com.intellij.platform.eel.provider.utils.EelPathUtils.getActualPath
|
||||
import com.intellij.platform.eel.provider.utils.fetchLoginShellEnvVariablesBlocking
|
||||
import com.intellij.platform.eel.provider.utils.where
|
||||
import com.intellij.platform.ide.progress.runWithModalProgressBlocking
|
||||
@@ -492,6 +493,10 @@ object MavenEelUtil {
|
||||
}
|
||||
|
||||
private fun EelFileSystemApi.tryMavenRoot(path: String): MavenInSpecificPath? {
|
||||
// we want to prevent paths like "\\wsl.localhost\Ubuntu\mnt\c\Something\something" from being leaked into the execution
|
||||
if (!path.isActualPathString()) {
|
||||
return null
|
||||
}
|
||||
val home = getPath(path).asNioPath()
|
||||
if (isValidMavenHome(home)) {
|
||||
MavenLog.LOG.debug("Maven home found at $path")
|
||||
@@ -499,4 +504,9 @@ object MavenEelUtil {
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun String.isActualPathString(): Boolean {
|
||||
val path = Path.of(this)
|
||||
return path == getActualPath(path)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user