[ijent] IJPL-232220 encode windows drive root as two-segment path

GitOrigin-RevId: 6f43db4cd3d6903c8144a621acded43504535929
This commit is contained in:
Mihail Buryakov
2026-02-04 01:51:43 +02:00
committed by intellij-monorepo-bot
parent cb29f205f7
commit 91a3a83da1
3 changed files with 28 additions and 5 deletions

View File

@@ -6,6 +6,7 @@ import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.diagnostic.trace
import com.intellij.openapi.project.Project
import com.intellij.platform.eel.EelDescriptor
import com.intellij.platform.eel.EelOsFamily
import com.intellij.platform.eel.EelPathBoundDescriptor
import com.intellij.platform.eel.annotations.MultiRoutingFileSystemPath
import com.intellij.platform.eel.isPosix
@@ -43,6 +44,8 @@ fun EelPath.asNioPath(project: Project?): @MultiRoutingFileSystemPath Path {
return asNioPath()
}
private val WINDOWS_DRIVE_PREFIX_REGEX = Regex("^\\w:")
/** See docs for [asNioPath] */
@Deprecated("It never returns null anymore")
@ApiStatus.Experimental
@@ -63,7 +66,17 @@ fun EelPath.asNioPathOrNull(): @MultiRoutingFileSystemPath Path? {
}
@MultiRoutingFileSystemPath
val result = parts.fold(root, Path::resolve)
val result = when (descriptor.osFamily) {
EelOsFamily.Windows -> {
if (WINDOWS_DRIVE_PREFIX_REGEX.containsMatchIn(this.root.toString())) {
(listOf("@", this.root.toString().take(1)) + parts).fold(root, Path::resolve)
}
else {
parts.fold(root, Path::resolve)
}
}
EelOsFamily.Posix -> parts.fold(root, Path::resolve)
}
LOG.trace {
"asNioPathOrNull(): path=$this basePath=$root result=$result"
}

View File

@@ -14,6 +14,7 @@ import java.nio.file.FileSystem
import java.nio.file.FileSystemAlreadyExistsException
import java.nio.file.Files
import java.util.concurrent.ConcurrentHashMap
import kotlin.io.path.pathString
class TcpEelMrfsBackend(private val scope: CoroutineScope) : MultiRoutingFileSystemBackend {
@@ -57,7 +58,7 @@ class TcpEelMrfsBackend(private val scope: CoroutineScope) : MultiRoutingFileSys
}
override fun getCustomRoots(): Collection<@MultiRoutingFileSystemPath String> {
return cache.keys.map { "${TcpEelConstants.TCP_PATH_PREFIX}$it" }
return cache.values.flatMap { it.rootDirectories }.map { it.pathString }
}
override fun getCustomFileStores(localFS: FileSystem): Collection<FileStore> {

View File

@@ -269,7 +269,7 @@ class IjentEphemeralRootAwareFileSystemProvider(
return ijentFsProvider
}
override fun wrapDelegatePath(delegatePath: Path?): Path? {
public override fun wrapDelegatePath(delegatePath: Path?): Path? {
if (delegatePath == null) return null
if (delegatePath is IjentNioPath) {
@@ -341,7 +341,11 @@ class IjentEphemeralRootAwareFileSystem(
}
override fun getRootDirectories(): Iterable<Path?> {
return if (useRootDirectoriesFromOriginalFs) originalFs.rootDirectories else listOf(Path(root.pathString))
return if (useRootDirectoriesFromOriginalFs) {
originalFs.rootDirectories
} else {
ijentFs.rootDirectories.map { rootAwareFileSystemProvider.wrapDelegatePath(it) }
}
}
override fun close() {
@@ -397,7 +401,12 @@ class IjentEphemeralRootAwareFileSystem(
}
EelOsFamily.Windows -> {
if (relativePath != null) {
arrayOf(relativePath.removePrefix("/"), *parts)
if (relativePath.startsWith("/@/")) {
arrayOf("${relativePath[3]}:${relativePath.drop(4)}", *parts)
}
else {
arrayOf(relativePath.removePrefix("/"), *parts)
}
}
else parts
}