File tree Expand file tree Collapse file tree 10 files changed +26
-9
lines changed Expand file tree Collapse file tree 10 files changed +26
-9
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
2
+ * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
3
3
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
4
4
*/
5
5
6
6
package kotlinx.io.files
7
7
8
+ import kotlinx.io.isWindows
8
9
import kotlin.test.*
9
10
10
11
class SmokeFileTestWindows {
11
12
@Test
12
13
fun isAbsolute () {
14
+ if (! isWindows) return
13
15
assertTrue(Path (" C:\\ " ).isAbsolute)
14
16
assertTrue(Path (" C:/" ).isAbsolute)
15
17
assertTrue(Path (" C:/../" ).isAbsolute)
@@ -21,6 +23,7 @@ class SmokeFileTestWindows {
21
23
22
24
@Test
23
25
fun getParent () {
26
+ if (! isWindows) return
24
27
assertNull(Path (" C:\\ " ).parent)
25
28
assertNull(Path (" a\\ b" ).parent?.parent)
26
29
assertEquals(Path (" \\\\ server" ), Path (" \\\\ server\\ share" ).parent)
@@ -30,6 +33,7 @@ class SmokeFileTestWindows {
30
33
31
34
@Test
32
35
fun trailingSeparatorsTrimming () {
36
+ if (! isWindows) return
33
37
assertEquals(" ." , Path (" .\\ " ).toString())
34
38
assertEquals(" C:\\ " , Path (" C:\\ " ).toString())
35
39
assertEquals(" C:\\ " , Path (" C:\\\\ " ).toString())
Original file line number Diff line number Diff line change @@ -71,3 +71,5 @@ fun Char.repeat(count: Int): String {
71
71
fun assertArrayEquals (a : ByteArray , b : ByteArray ) {
72
72
assertEquals(a.contentToString(), b.contentToString())
73
73
}
74
+
75
+ expect val isWindows: Boolean
Original file line number Diff line number Diff line change @@ -21,3 +21,5 @@ public actual open class IOException actual constructor(
21
21
public actual open class EOFException actual constructor(message : String? ) : IOException(message) {
22
22
public actual constructor () : this (null )
23
23
}
24
+
25
+ internal val isWindows_ = os.platform() == " win32"
Original file line number Diff line number Diff line change 5
5
6
6
package kotlinx.io.files
7
7
8
- import kotlinx.io.IOException
9
- import kotlinx.io.RawSink
10
- import kotlinx.io.RawSource
8
+ import kotlinx.io.*
9
+ import kotlinx.io.buffer
10
+ import kotlinx.io.fs
11
+ import kotlinx.io.os
11
12
12
13
public actual val SystemFileSystem : FileSystem = object : SystemFileSystemImpl () {
13
14
override fun exists (path : Path ): Boolean {
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ public actual class Path internal constructor(
17
17
get() {
18
18
check(pathLib != = null ) { " Path module not found" }
19
19
if (path.isEmpty()) return null
20
- if (isWindows ) {
20
+ if (isWindows_ ) {
21
21
if (! path.contains(UnixPathSeparator ) && ! path.contains(WindowsPathSeparator )) {
22
22
return null
23
23
}
@@ -74,8 +74,6 @@ public actual val SystemPathSeparator: Char by lazy {
74
74
75
75
private const val WindowsPathSeparator : Char = ' \\ '
76
76
private const val UnixPathSeparator : Char = ' /'
77
- private val isWindows = os.platform() == " win32"
78
-
79
77
public actual fun Path (path : String ): Path {
80
78
return Path (path, null )
81
79
}
@@ -164,7 +162,7 @@ private fun isUnc(path: String): Boolean {
164
162
}
165
163
166
164
internal fun removeTrailingSeparators (path : String ): String {
167
- if (isWindows ) {
165
+ if (isWindows_ ) {
168
166
// don't trim the path separator right after the drive name
169
167
val limit = if (path.length > 1 ) {
170
168
if (path[1 ] == ' :' ) {
Original file line number Diff line number Diff line change 3
3
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
4
4
*/
5
5
6
- package kotlinx.io.files
6
+ package kotlinx.io
7
7
8
8
internal val os: dynamic
9
9
get(): dynamic {
Original file line number Diff line number Diff line change @@ -47,3 +47,5 @@ actual fun tempFileName(): String {
47
47
return fullpath
48
48
}
49
49
}
50
+
51
+ actual val isWindows: Boolean = isWindows_
Original file line number Diff line number Diff line change @@ -24,3 +24,5 @@ actual fun tempFileName(): String {
24
24
fun assertByteArrayEquals (expectedUtf8 : String , b : ByteArray ) {
25
25
assertEquals(expectedUtf8, b.toString(Charsets .UTF_8 ))
26
26
}
27
+
28
+ actual val isWindows: Boolean = System .getProperty(" os.name" )?.startsWith(" Windows" ) ? : false
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import kotlinx.cinterop.UnsafeNumber
11
11
import kotlinx.io.files.SystemTemporaryDirectory
12
12
import platform.posix.F_OK
13
13
import platform.posix.access
14
+ import kotlin.experimental.ExperimentalNativeApi
14
15
import kotlin.random.Random
15
16
16
17
@OptIn(UnsafeNumber ::class , ExperimentalStdlibApi ::class )
@@ -25,3 +26,6 @@ actual fun tempFileName(): String {
25
26
}
26
27
throw IOException (" Failed to generate temp file name" )
27
28
}
29
+
30
+ @OptIn(ExperimentalNativeApi ::class )
31
+ actual val isWindows: Boolean = Platform .osFamily == OsFamily .WINDOWS
Original file line number Diff line number Diff line change @@ -8,3 +8,5 @@ package kotlinx.io
8
8
import kotlinx.io.files.unsupported
9
9
10
10
actual fun tempFileName (): String = unsupported()
11
+
12
+ actual val isWindows: Boolean = false
You can’t perform that action at this time.
0 commit comments