mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 15:06:56 +07:00
IJPL-149878 IJent WSL FS refactoring: use tracing FS everywhere in IjentWslNioFsToggler
It fixes the benchmark test that used to measure IJent in case of the alleged WSL test. GitOrigin-RevId: 7a7006ce3a60961ecf8b0ab8a4bc2fb4aa48bb01
This commit is contained in:
committed by
intellij-monorepo-bot
parent
70f6a49e54
commit
98845870c6
@@ -11,6 +11,12 @@ import java.nio.file.attribute.FileAttribute
|
||||
import java.nio.file.attribute.FileAttributeView
|
||||
import java.nio.file.spi.FileSystemProvider
|
||||
|
||||
/**
|
||||
* A contract of this file system: every instance of [TracingFileSystemProvider] and [TracingFileSystem] writes to
|
||||
* the same statistics collectors.
|
||||
* Given that [delegate] is the same, measures from instances of `TracingFileSystemProvider(delegate)` are written into the single place.
|
||||
* It's possible to get rid of this contract, but usages should be refactored then.
|
||||
*/
|
||||
class TracingFileSystemProvider(
|
||||
val delegate: FileSystemProvider,
|
||||
) : DelegatingFileSystemProvider<TracingFileSystemProvider, TracingFileSystem>(), RoutingAwareFileSystemProvider {
|
||||
|
||||
@@ -4,6 +4,7 @@ package com.intellij.execution.wsl.ijent.nio.toggle
|
||||
import com.intellij.execution.wsl.WSLDistribution
|
||||
import com.intellij.execution.wsl.WslDistributionManager
|
||||
import com.intellij.execution.wsl.WslIjentManager
|
||||
import com.intellij.execution.wsl.ijent.nio.IjentWslNioFileSystem
|
||||
import com.intellij.execution.wsl.ijent.nio.IjentWslNioFileSystemProvider
|
||||
import com.intellij.platform.core.nio.fs.MultiRoutingFileSystemProvider
|
||||
import com.intellij.platform.ijent.IjentId
|
||||
@@ -63,7 +64,7 @@ internal class IjentWslNioFsToggleStrategy(
|
||||
|
||||
private suspend fun handleWslDistributionAddition(distro: WSLDistribution) {
|
||||
val ijentApi = WslIjentManager.instanceAsync().getIjentApi(distro, null, false)
|
||||
enable(distro, ijentApi.id)
|
||||
switchToIjentFs(distro, ijentApi.id)
|
||||
}
|
||||
|
||||
private fun handleWslDistributionDeletion(distro: WSLDistribution) {
|
||||
@@ -73,7 +74,7 @@ internal class IjentWslNioFsToggleStrategy(
|
||||
}
|
||||
}
|
||||
|
||||
fun enable(distro: WSLDistribution, ijentId: IjentId) {
|
||||
fun switchToIjentFs(distro: WSLDistribution, ijentId: IjentId) {
|
||||
val ijentFsProvider = TracingFileSystemProvider(IjentNioFileSystemProvider.getInstance())
|
||||
try {
|
||||
ijentFsProvider.newFileSystem(ijentId.uri, null)
|
||||
@@ -82,14 +83,14 @@ internal class IjentWslNioFsToggleStrategy(
|
||||
// Nothing.
|
||||
}
|
||||
|
||||
ownFileSystems.compute(distro) { underlyingProvider, ownFs, actualFs ->
|
||||
if (actualFs?.provider()?.unwrapIjentWslNioFileSystemProvider() != null) {
|
||||
ownFileSystems.compute(distro) { underlyingProvider, _, actualFs ->
|
||||
if (actualFs is IjentWslNioFileSystem) {
|
||||
actualFs
|
||||
}
|
||||
else {
|
||||
IjentWslNioFileSystemProvider(
|
||||
ijentId = ijentId,
|
||||
wslLocalRoot = underlyingProvider.getFileSystem(URI.create("file:/")).getPath(distro.getWindowsPath("/")),
|
||||
wslLocalRoot = underlyingProvider.getLocalFileSystem().getPath(distro.getWindowsPath("/")),
|
||||
ijentFsProvider = ijentFsProvider,
|
||||
originalFsProvider = TracingFileSystemProvider(underlyingProvider),
|
||||
).getFileSystem(ijentId.uri)
|
||||
@@ -97,15 +98,9 @@ internal class IjentWslNioFsToggleStrategy(
|
||||
}
|
||||
}
|
||||
|
||||
fun disable(distro: WSLDistribution) {
|
||||
ownFileSystems.compute(distro) { _, ownFs, actualFs ->
|
||||
val actualIjentWslFsProvider = actualFs?.provider()?.unwrapIjentWslNioFileSystemProvider()
|
||||
if (actualIjentWslFsProvider != null) {
|
||||
actualIjentWslFsProvider.originalFsProvider.getFileSystem(URI.create("file:/"))
|
||||
}
|
||||
else {
|
||||
actualFs
|
||||
}
|
||||
fun switchToTracingWsl9pFs(distro: WSLDistribution) {
|
||||
ownFileSystems.compute(distro) { underlyingProvider, _, _ ->
|
||||
TracingFileSystemProvider(underlyingProvider).getLocalFileSystem()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,12 +109,8 @@ internal class IjentWslNioFsToggleStrategy(
|
||||
}
|
||||
}
|
||||
|
||||
private fun FileSystemProvider.unwrapIjentWslNioFileSystemProvider(): IjentWslNioFileSystemProvider? =
|
||||
when (this) {
|
||||
is IjentWslNioFileSystemProvider -> this
|
||||
is TracingFileSystemProvider -> delegate.unwrapIjentWslNioFileSystemProvider()
|
||||
else -> null
|
||||
}
|
||||
private fun FileSystemProvider.getLocalFileSystem(): FileSystem =
|
||||
getFileSystem(URI.create("file:/"))
|
||||
|
||||
/**
|
||||
* This class accesses two synchronization primitives simultaneously.
|
||||
|
||||
@@ -42,13 +42,16 @@ class IjentWslNioFsToggler(private val coroutineScope: CoroutineScope) {
|
||||
strategy.enableForAllWslDistributions()
|
||||
}
|
||||
|
||||
fun enable(distro: WSLDistribution, ijentId: IjentId) {
|
||||
strategy?.enable(distro, ijentId)
|
||||
@TestOnly
|
||||
fun switchToIjentFs(distro: WSLDistribution, ijentId: IjentId) {
|
||||
strategy ?: error("Not available")
|
||||
strategy.switchToIjentFs(distro, ijentId)
|
||||
}
|
||||
|
||||
// TODO Disable when IJent exits.
|
||||
fun disable(distro: WSLDistribution) {
|
||||
strategy?.disable(distro)
|
||||
@TestOnly
|
||||
fun switchToTracingWsl9pFs(distro: WSLDistribution) {
|
||||
strategy ?: error("Not available")
|
||||
strategy.switchToTracingWsl9pFs(distro)
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
@@ -60,7 +63,7 @@ class IjentWslNioFsToggler(private val coroutineScope: CoroutineScope) {
|
||||
private val strategy = run {
|
||||
val defaultProvider = FileSystems.getDefault().provider()
|
||||
when {
|
||||
!WslIjentAvailabilityService.Companion.getInstance().useIjentForWslNioFileSystem() -> null
|
||||
!WslIjentAvailabilityService.getInstance().useIjentForWslNioFileSystem() -> null
|
||||
|
||||
defaultProvider.javaClass.name == MultiRoutingFileSystemProvider::class.java.name -> {
|
||||
IjentWslNioFsToggleStrategy(defaultProvider, coroutineScope)
|
||||
|
||||
Reference in New Issue
Block a user