-
Notifications
You must be signed in to change notification settings - Fork 72
Replace stat call with NSFileManager API on Apple target #298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -5,10 +5,28 @@ | |||
|
|
||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No special Gradle configuring for the new source set?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the old one: kotlinx-io/build-logic/src/main/kotlin/kotlinx/io/conventions/kotlinx-io-multiplatform.gradle.kts Line 76 in bae3fe3
|
||||
| package kotlinx.io.files | ||||
|
|
||||
| import kotlinx.cinterop.ExperimentalForeignApi | ||||
| import kotlinx.cinterop.toKString | ||||
| import platform.posix.getenv | ||||
| import kotlinx.cinterop.* | ||||
| import kotlinx.io.IOException | ||||
| import platform.posix.* | ||||
|
|
||||
| @OptIn(ExperimentalForeignApi::class) | ||||
| public actual val SystemTemporaryDirectory: Path | ||||
| get() = Path(getenv("TMPDIR")?.toKString() ?: getenv("TMP")?.toKString() ?: "") | ||||
|
|
||||
| @OptIn(ExperimentalForeignApi::class, UnsafeNumber::class) | ||||
| internal actual fun metadataOrNullImpl(path: Path): FileMetadata? { | ||||
| memScoped { | ||||
| val struct_stat = alloc<stat>() | ||||
| if (stat(path.path, struct_stat.ptr) != 0) { | ||||
| if (errno == ENOENT) return null | ||||
| throw IOException("stat failed to ${path.path}: ${strerror(errno)?.toKString()}") | ||||
| } | ||||
| val mode = struct_stat.st_mode.toInt() | ||||
| val isFile = (mode and S_IFMT) == S_IFREG | ||||
| return FileMetadata( | ||||
| isRegularFile = isFile, | ||||
| isDirectory = (mode and S_IFMT) == S_IFDIR, | ||||
| if (isFile) struct_stat.st_size.toLong() else -1L | ||||
| ) | ||||
| } | ||||
| } | ||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is invoking
NSFileManager.defaultManager()is a cheap operation?Can we lazily cache default manager?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just a getter: https://github.com/apple/swift-corelibs-foundation/blob/77af9c5a984f40e186c0ba127cff88f2a2588c15/Sources/Foundation/FileManager.swift#L43
Not sure if we can gain much by caching it