Skip to content

Commit 7ba61cb

Browse files
committed
Use anonymous system FS subclasses
1 parent 76506b0 commit 7ba61cb

File tree

3 files changed

+5
-22
lines changed

3 files changed

+5
-22
lines changed

core/js/src/files/FileSystemJs.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ internal val os: dynamic
2525
}
2626
}
2727

28-
private class JsFileSystem : SystemFileSystemImpl() {
29-
companion object {
30-
val Instance = JsFileSystem()
31-
}
32-
28+
internal actual val SystemFileSystem: FileSystem = object : SystemFileSystemImpl() {
3329
override fun exists(path: Path): Boolean {
3430
check(fs !== null) { "Module 'fs' was not found" }
3531
return fs.existsSync(path.path) as Boolean
@@ -104,8 +100,6 @@ private class JsFileSystem : SystemFileSystemImpl() {
104100
}
105101
}
106102

107-
internal actual val SystemFileSystem: FileSystem = JsFileSystem.Instance
108-
109103
internal actual val SystemTemporaryDirectoryImpl: Path
110104
get() {
111105
check(os !== null) { "Module 'os' was not found" }

core/jvm/src/files/FileSystemJvm.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ private val mover: Mover by lazy {
4141
}
4242
}
4343

44-
private class JvmFileSystem : SystemFileSystemImpl() {
45-
companion object {
46-
val Instance = JvmFileSystem()
47-
}
44+
@JvmField
45+
internal actual val SystemFileSystem: FileSystem = object : SystemFileSystemImpl() {
4846

4947
override fun exists(path: Path): Boolean {
5048
return path.file.exists()
@@ -64,7 +62,7 @@ private class JvmFileSystem : SystemFileSystemImpl() {
6462

6563
override fun createDirectories(path: Path, mustCreate: Boolean) {
6664
if (!path.file.mkdirs() && mustCreate) {
67-
throw IOException("Path already exist: ${path}")
65+
throw IOException("Path already exist: $path")
6866
}
6967
}
7068

@@ -79,8 +77,6 @@ private class JvmFileSystem : SystemFileSystemImpl() {
7977
}
8078
}
8179

82-
internal actual val SystemFileSystem: FileSystem = JvmFileSystem.Instance
83-
8480
internal actual val SystemTemporaryDirectoryImpl: Path
8581
get() = Path(System.getProperty("java.io.tmpdir"))
8682

core/native/src/files/FileSystemNative.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ import kotlinx.cinterop.*
99
import kotlinx.io.IOException
1010
import platform.posix.*
1111

12-
private class NativeFileSystem : SystemFileSystemImpl() {
13-
companion object {
14-
val Instance = NativeFileSystem()
15-
}
16-
12+
internal actual val SystemFileSystem: FileSystem = object : SystemFileSystemImpl() {
1713
override fun exists(path: Path): Boolean {
1814
return access(path.path, F_OK) == 0
1915
}
@@ -82,9 +78,6 @@ internal expect fun atomicMoveImpl(source: Path, destination: Path)
8278

8379
internal expect fun mkdirImpl(path: String)
8480

85-
internal actual val SystemFileSystem: FileSystem
86-
get() = NativeFileSystem.Instance
87-
8881
public actual open class FileNotFoundException actual constructor(
8982
message: String?
9083
) : IOException(message)

0 commit comments

Comments
 (0)