Skip to content

Commit 828fc1f

Browse files
committed
Fix stupid stat bug wreaking havoc on macOS
When interrogating the output struct, do it *before* it falls out of scope. :-e
1 parent f6fb394 commit 828fc1f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/posixMain/kotlin/File.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ actual class File actual constructor(private val rawPath: String) {
1313
actual val isDirectory: Boolean get() = isMode(S_IFDIR)
1414
actual val isRoot: Boolean = path == SLASH
1515

16-
@OptIn(ExperimentalForeignApi::class)
16+
@OptIn(ExperimentalForeignApi::class, UnsafeNumber::class)
1717
private fun isMode(modeBits: Int): Boolean {
18-
val statResult = memScoped {
18+
val statMode = memScoped {
1919
val statResult = alloc<stat>()
2020
stat(path, statResult.ptr)
21-
statResult
21+
statResult.st_mode.toInt()
2222
}
23-
return (statResult.st_mode.toInt() and modeBits) != 0
23+
return (statMode and modeBits) != 0
2424
}
2525

2626
@OptIn(ExperimentalForeignApi::class)

0 commit comments

Comments
 (0)