IJPL-171655 IJent WSL FS: don't query IJent for obvious information about roots

It allows postponing initialization of IJent through `IjentFailSafeFileSystemPosixApi` from inside File chooser, when no WSL node is expanded.


(cherry picked from commit aafe453201b0e8725d8ce82b89f4d796965135d7)

IJ-CR-149490

GitOrigin-RevId: 783f99bd291b2aee071237a250deec26349a2229
This commit is contained in:
Vladimir Lagunov
2024-11-15 17:55:49 +01:00
committed by intellij-monorepo-bot
parent 5a58a3f2bf
commit 36558d7ec6
2 changed files with 19 additions and 6 deletions

View File

@@ -9,7 +9,7 @@ import java.nio.file.attribute.UserPrincipalLookupService
*/
class IjentWslNioFileSystem(
private val provider: IjentWslNioFileSystemProvider,
private val wslId: String,
internal val wslId: String,
private val ijentFs: FileSystem,
private val originalFs: FileSystem,
) : FileSystem() {
@@ -28,11 +28,18 @@ class IjentWslNioFileSystem(
override fun getSeparator(): String = originalFs.separator
override fun getRootDirectories(): Iterable<Path> =
LinkedHashSet<Path>().apply {
addAll(originalFs.rootDirectories)
addAll(ijentFs.rootDirectories)
}
override fun getRootDirectories(): Iterable<Path> {
// It is known that `originalFs.rootDirectories` always returns all WSL drives.
// Also, it is known that `ijentFs.rootDirectories` returns a single WSL drive,
// which is already mentioned in `originalFs.rootDirectories`.
//
// `ijentFs` is usually represented by `IjentFailSafeFileSystemPosixApi`,
// which launches IJent and the corresponding WSL containers lazily.
//
// This function avoids fetching root directories directly from IJent.
// This way, various UI file trees don't start all WSL containers during loading the file system root.
return originalFs.rootDirectories
}
override fun getFileStores(): Iterable<FileStore> =
originalFs.fileStores + ijentFs.fileStores

View File

@@ -41,6 +41,12 @@ class IjentWslNioPath(
override fun toAbsolutePath(): IjentWslNioPath = delegate.toAbsolutePath().toIjentWslPath()
override fun toRealPath(vararg options: LinkOption): IjentWslNioPath {
when (normalize().toString()) {
"\\\\wsl$\\${fileSystem.wslId}\\", "\\\\wsl.localhost\\${fileSystem.wslId}\\" -> {
return this
}
}
val ijentNioPath = fileSystem.provider().toIjentNioPath(this)
val ijentNioRealPath = ijentNioPath.toRealPath(*options)
val originalPath = fileSystem.provider().toOriginalPath(ijentNioRealPath)