Skip to content

Commit

Permalink
Fix MultiplatformSystem.readFileAsUtf8 not supporting special files (
Browse files Browse the repository at this point in the history
  • Loading branch information
ajalt authored Jul 9, 2024
1 parent 00b3abe commit 93cf729
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Fixed
- Fix markdown rendering not supporting math blocks [(#182)](https://github.com/ajalt/mordant/issues/182)
- Fix exception thrown when using `readEvent` in raw mode when some windows terminals lose focus
- Fix `MultiplatformSystem.readFileAsUtf8` not supporting special files on JVM on Linux


## 2.7.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import com.github.ajalt.mordant.internal.syscalls.nativeimage.SyscallHandlerNati
import com.github.ajalt.mordant.internal.syscalls.nativeimage.SyscallHandlerNativeImageWindows
import com.github.ajalt.mordant.terminal.*
import java.io.File
import java.io.IOException
import java.lang.management.ManagementFactory
import java.nio.file.Path
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicReference
import kotlin.io.path.readText
import kotlin.system.exitProcess

private class JvmAtomicRef<T>(value: T) : MppAtomicRef<T> {
Expand Down Expand Up @@ -151,7 +154,9 @@ internal actual fun exitProcessMpp(status: Int) {
}

internal actual fun readFileIfExists(filename: String): String? {
val file = File(filename)
if (!file.isFile) return null
return file.bufferedReader().use { it.readText() }
return try {
Path.of(filename).readText()
} catch (e: IOException) {
null
}
}

0 comments on commit 93cf729

Please sign in to comment.