diff --git a/platform/eel/tests/com/intellij/platform/eel/path/EelAbsolutePathTest.kt b/platform/eel/tests/com/intellij/platform/eel/path/EelAbsolutePathTest.kt index c02e24b0454c..73fb3111634c 100644 --- a/platform/eel/tests/com/intellij/platform/eel/path/EelAbsolutePathTest.kt +++ b/platform/eel/tests/com/intellij/platform/eel/path/EelAbsolutePathTest.kt @@ -1,9 +1,7 @@ // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.platform.eel.path -import com.intellij.platform.eel.EelResult import io.kotest.matchers.shouldBe -import io.kotest.matchers.types.shouldBeInstanceOf import org.junit.jupiter.api.DynamicTest import org.junit.jupiter.api.DynamicTest.dynamicTest import org.junit.jupiter.api.TestFactory @@ -35,10 +33,7 @@ class EelAbsolutePathTest { for (rawPath in (unixPaths + windowsPaths)) { add(dynamicTest(rawPath) { - val eelPath = EelPath.Absolute - .parse(rawPath, null) - .shouldBeInstanceOf>() - .value + val eelPath = EelPath.Absolute.parseE(rawPath, null) eelPath.toString() shouldBe rawPath }) } diff --git a/platform/eel/tests/com/intellij/platform/eel/path/EelRelativePathTest.kt b/platform/eel/tests/com/intellij/platform/eel/path/EelRelativePathTest.kt index 457ca354ad10..b1c87a782cc2 100644 --- a/platform/eel/tests/com/intellij/platform/eel/path/EelRelativePathTest.kt +++ b/platform/eel/tests/com/intellij/platform/eel/path/EelRelativePathTest.kt @@ -30,8 +30,8 @@ class EelRelativePathTest { abc/./def/../ghi, abc/ghi ./abc/def/../ghi, abc/ghi """) fun normalize(source: String?, expected: String?) { - val sourcePath = EelPath.Relative.parse(source ?: "").getOrThrow() - val expectedPath = EelPath.Relative.parse(expected ?: "").getOrThrow() + val sourcePath = EelPath.Relative.parseE(source ?: "") + val expectedPath = EelPath.Relative.parseE(expected ?: "") sourcePath.normalize() should be(expectedPath) } @@ -39,9 +39,9 @@ class EelRelativePathTest { inner class getChild { @Test fun positive() { - val empty = EelPath.Relative.build().getOrThrow() - empty.getChild("a") should be(EelPath.Relative.build("a")) - empty.getChild("a").getOrThrow().getChild("bc") should be(EelPath.Relative.build("a", "bc")) + val empty = EelPath.Relative.buildE() + empty.getChildE("a") should be(EelPath.Relative.buildE("a")) + empty.getChildE("a").getChildE("bc") should be(EelPath.Relative.buildE("a", "bc")) } } @@ -49,11 +49,11 @@ class EelRelativePathTest { inner class resolve { @Test fun `parent directory should persist`() { - val path = EelPath.Relative.parse("abc/..").getOrThrow() - val targetPath = EelPath.Relative.parse("def").getOrThrow() + val path = EelPath.Relative.parseE("abc/..") + val targetPath = EelPath.Relative.parseE("def") withClue("IjentPath.Relative.resolve must not normalize paths") { - EelPath.Relative.parse("abc/../def") should be(path.resolve(targetPath)) + EelPath.Relative.parseE("abc/../def") should be(path.resolveE(targetPath)) } } } @@ -63,15 +63,15 @@ class EelRelativePathTest { @Test fun positive() { val raw = "a/b/c" - val path = EelPath.Relative.parse(raw).getOrThrow() - val expected = EelPath.Relative.parse("b").getOrThrow() + val path = EelPath.Relative.parseE(raw) + val expected = EelPath.Relative.parseE("b") expected should be(path.getName(1)) } @Test fun `out of bound`() { val raw = "a/b/c" - val path = EelPath.Relative.parse(raw).getOrThrow() + val path = EelPath.Relative.parseE(raw) shouldThrowAny { path.getName(10) @@ -84,14 +84,14 @@ class EelRelativePathTest { @ParameterizedTest @ValueSource(strings = ["a/b", "a/b/c"]) fun `is not null`(raw: String) { - val path = EelPath.Relative.parse(raw).getOrThrow() + val path = EelPath.Relative.parseE(raw) path.parent shouldNot be(null) } @ParameterizedTest @ValueSource(strings = ["", "a"]) fun `is null`(raw: String) { - val path = EelPath.Relative.parse(raw).getOrThrow() + val path = EelPath.Relative.parseE(raw) path.parent should be(null) } } diff --git a/platform/eelProvider/src/com/intellij/platform/eel/impl/local/LocalEelApiImpl.kt b/platform/eelProvider/src/com/intellij/platform/eel/impl/local/LocalEelApiImpl.kt index 47ebb39eb7ac..b45ca48e2f0a 100644 --- a/platform/eelProvider/src/com/intellij/platform/eel/impl/local/LocalEelApiImpl.kt +++ b/platform/eelProvider/src/com/intellij/platform/eel/impl/local/LocalEelApiImpl.kt @@ -5,16 +5,15 @@ import com.intellij.openapi.util.SystemInfo import com.intellij.platform.eel.* import com.intellij.platform.eel.fs.EelFileSystemPosixApi import com.intellij.platform.eel.fs.EelFileSystemWindowsApi -import com.intellij.platform.eel.fs.getPath +import com.intellij.platform.eel.fs.getPathE import com.intellij.platform.eel.path.EelPath -import com.intellij.platform.eel.path.getOrThrow import com.intellij.platform.eel.provider.EelUserPosixInfoImpl import com.intellij.platform.eel.provider.EelUserWindowsInfoImpl import java.nio.file.Path internal class LocalEelPathMapper(private val eelApi: EelApi) : EelPathMapper { override fun getOriginalPath(path: Path): EelPath.Absolute { - return eelApi.fs.getPath(path.toString()).getOrThrow() + return eelApi.fs.getPathE(path.toString()) } override fun toNioPath(path: EelPath.Absolute): Path { diff --git a/platform/eelProvider/src/com/intellij/platform/eel/provider/utils/eelProcessUtils.kt b/platform/eelProvider/src/com/intellij/platform/eel/provider/utils/eelProcessUtils.kt index ae17b75e31a5..22c0441edcbe 100644 --- a/platform/eelProvider/src/com/intellij/platform/eel/provider/utils/eelProcessUtils.kt +++ b/platform/eelProvider/src/com/intellij/platform/eel/provider/utils/eelProcessUtils.kt @@ -3,9 +3,8 @@ package com.intellij.platform.eel.provider.utils import com.intellij.execution.process.ProcessOutput import com.intellij.platform.eel.* -import com.intellij.platform.eel.fs.getPath +import com.intellij.platform.eel.fs.getPathE import com.intellij.platform.eel.path.EelPath -import com.intellij.platform.eel.path.getOrThrow import com.intellij.util.io.computeDetached import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.channels.consumeEach @@ -85,6 +84,6 @@ suspend fun EelApi.where(exe: String): EelPath.Absolute? { return null } else { - return fs.getPath(result.stdout).getOrThrow() + return fs.getPathE(result.stdout) } } \ No newline at end of file diff --git a/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystem.kt b/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystem.kt index 20e83b07f681..7239cf981b32 100644 --- a/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystem.kt +++ b/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystem.kt @@ -2,7 +2,6 @@ package com.intellij.platform.ijent.community.impl.nio import com.intellij.platform.eel.path.EelPath -import com.intellij.platform.eel.path.getOrThrow import com.intellij.platform.ijent.fs.IjentFileSystemApi import com.intellij.platform.ijent.fs.IjentFileSystemPosixApi import com.intellij.platform.ijent.fs.IjentFileSystemWindowsApi @@ -71,10 +70,8 @@ class IjentNioFileSystem internal constructor( is IjentFileSystemPosixApi -> EelPath.Absolute.OS.UNIX is IjentFileSystemWindowsApi -> EelPath.Absolute.OS.WINDOWS } - return EelPath.parse(first, os) - .getOrThrow() - .resolve(EelPath.Relative.build(*more).getOrThrow()) - .getOrThrow() + return EelPath.parseE(first, os) + .resolveE(EelPath.Relative.buildE(*more)) .toNioPath() } diff --git a/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystemProvider.kt b/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystemProvider.kt index 728870c9a86b..5f423b269219 100644 --- a/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystemProvider.kt +++ b/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystemProvider.kt @@ -10,7 +10,6 @@ import com.intellij.platform.eel.fs.EelFileSystemPosixApi.CreateDirectoryExcepti import com.intellij.platform.eel.fs.EelFileSystemPosixApi.CreateSymbolicLinkException import com.intellij.platform.eel.fs.EelPosixFileInfo.Type.Symlink import com.intellij.platform.eel.path.EelPath -import com.intellij.platform.eel.path.getOrThrow import com.intellij.platform.eel.provider.EelFsResultImpl import com.intellij.platform.ijent.community.impl.nio.IjentNioFileSystemProvider.Companion.newFileSystemMap import com.intellij.platform.ijent.community.impl.nio.IjentNioFileSystemProvider.UnixFilePermissionBranch.* @@ -206,7 +205,7 @@ class IjentNioFileSystemProvider : FileSystemProvider() { .getOrThrowFileSystemException() .asSequence() .map { (childName, childStat) -> - val childIjentPath = dir.eelPath.getChild(childName).getOrThrow() + val childIjentPath = dir.eelPath.getChildE(childName) val childAttrs = when (childStat) { is EelPosixFileInfo -> IjentNioPosixFileAttributes(childStat) is EelWindowsFileInfo -> TODO() @@ -220,7 +219,7 @@ class IjentNioFileSystemProvider : FileSystemProvider() { .getOrThrowFileSystemException() .asSequence() .map { childName -> - val childIjentPath = dir.eelPath.getChild(childName).getOrThrow() + val childIjentPath = dir.eelPath.getChildE(childName) IjentNioPath(childIjentPath, nioFs, null) } } diff --git a/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystemUtil.kt b/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystemUtil.kt index 999c9c5737e9..a65d946d6357 100644 --- a/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystemUtil.kt +++ b/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystemUtil.kt @@ -8,7 +8,6 @@ import com.intellij.platform.eel.fs.EelFileSystemApi import com.intellij.platform.eel.fs.EelFsError import com.intellij.platform.eel.fs.EelOpenedFile import com.intellij.platform.eel.path.EelPath -import com.intellij.platform.eel.path.getOrThrow import com.intellij.util.text.nullize import kotlinx.coroutines.Dispatchers import java.io.IOException @@ -55,7 +54,7 @@ internal fun Path.toEelPath(): EelPath = isAbsolute -> throw InvalidPathException(toString(), "This path can't be converted to IjentPath") - else -> EelPath.Relative.parse(toString()).getOrThrow() + else -> EelPath.Relative.parseE(toString()) } internal fun fsBlocking(body: suspend () -> T): T = invokeSuspending(body) diff --git a/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioPath.kt b/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioPath.kt index 3973aa97424e..0d1bffdcfb3f 100644 --- a/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioPath.kt +++ b/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioPath.kt @@ -3,7 +3,6 @@ package com.intellij.platform.ijent.community.impl.nio import com.intellij.platform.core.nio.fs.BasicFileAttributesHolder2 import com.intellij.platform.eel.path.EelPath -import com.intellij.platform.eel.path.getOrThrow import java.net.URI import java.nio.file.* import java.nio.file.attribute.BasicFileAttributes @@ -40,8 +39,7 @@ class IjentNioPath internal constructor( override fun getFileName(): IjentNioPath? = EelPath.Relative - .parse(eelPath.fileName) - .getOrThrow() + .parseE(eelPath.fileName) .toNioPath() .takeIf { it.nameCount > 0 } @@ -85,20 +83,20 @@ class IjentNioPath internal constructor( override fun normalize(): IjentNioPath = when (eelPath) { - is EelPath.Absolute -> eelPath.normalize().getOrThrow().toNioPath() + is EelPath.Absolute -> eelPath.normalizeE().toNioPath() is EelPath.Relative -> eelPath.normalize().toNioPath() } override fun resolve(other: Path): IjentNioPath = when (val otherIjentPath = other.toEelPath()) { is EelPath.Absolute -> otherIjentPath.toNioPath() // TODO is it the desired behaviour? - is EelPath.Relative -> eelPath.resolve(otherIjentPath).getOrThrow().toNioPath() + is EelPath.Relative -> eelPath.resolveE(otherIjentPath).toNioPath() } override fun relativize(other: Path): IjentNioPath = when (val otherIjentPath = other.toEelPath()) { is EelPath.Absolute -> when (eelPath) { - is EelPath.Absolute -> eelPath.relativize(otherIjentPath).getOrThrow().toNioPath() + is EelPath.Absolute -> eelPath.relativizeE(otherIjentPath).toNioPath() is EelPath.Relative -> throw InvalidPathException("$this.relativize($other)", "Can't relativize these paths") } @@ -127,7 +125,7 @@ class IjentNioPath internal constructor( override fun toRealPath(vararg options: LinkOption): IjentNioPath = when (eelPath) { is EelPath.Absolute -> - eelPath.normalize().getOrThrow() + eelPath.normalizeE() .let { normalizedPath -> if (LinkOption.NOFOLLOW_LINKS in options) normalizedPath diff --git a/platform/platform-impl/src/com/intellij/execution/eel/EelApiWithPathsMapping.kt b/platform/platform-impl/src/com/intellij/execution/eel/EelApiWithPathsMapping.kt index 34b2284e0f4c..82f69635fac9 100644 --- a/platform/platform-impl/src/com/intellij/execution/eel/EelApiWithPathsMapping.kt +++ b/platform/platform-impl/src/com/intellij/execution/eel/EelApiWithPathsMapping.kt @@ -7,8 +7,12 @@ import com.intellij.platform.core.nio.fs.MultiRoutingFsPath import com.intellij.platform.eel.* import com.intellij.platform.eel.EelExecApi.ExecuteProcessError import com.intellij.platform.eel.fs.getPath +import com.intellij.platform.eel.fs.EelFileSystemApi +import com.intellij.platform.eel.fs.getPathE import com.intellij.platform.eel.path.EelPath import com.intellij.platform.eel.path.getOrThrow +import com.intellij.util.awaitCancellationAndInvoke +import kotlinx.coroutines.CoroutineScope import org.jetbrains.annotations.ApiStatus.Internal import java.nio.file.Path import kotlin.io.path.pathString @@ -51,7 +55,7 @@ private class EelEphemeralRootAwareMapper( private val eelApi: EelApiBase, ) : EelPathMapper { override fun getOriginalPath(path: Path): EelPath.Absolute? { - return path.toEphemeralRootAwarePath()?.originalPath?.let { eelApi.fs.getPath(it.toString()).getOrThrow() } + return path.toEphemeralRootAwarePath()?.originalPath?.let { eelApi.fs.getPathE(it.toString()) } } override fun toNioPath(path: EelPath.Absolute): Path {