-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added FileSystem interface providing basic operations on paths: reading/writing files, creating directories, moving and deleting files and directories, and gathering fs node metadata. * Provided default FileSystem implementation - SystemFileSystem * Extended Path API to allow getting parent paths and constructing children's paths using platform-dependent APIs under the hood. * Added API to get path to the system temporary directory Closes: #206 #211 #212 #183 #214 --------- Co-authored-by: Jeff Lockhart <[email protected]>
- Loading branch information
Showing
29 changed files
with
1,461 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
package kotlinx.io.files | ||
|
||
import kotlinx.cinterop.ExperimentalForeignApi | ||
import kotlinx.cinterop.toKString | ||
import platform.posix.__posix_basename | ||
import platform.posix.dirname | ||
|
||
@OptIn(ExperimentalForeignApi::class) | ||
internal actual fun dirnameImpl(path: String): String { | ||
return dirname(path)?.toKString() ?: "" | ||
} | ||
|
||
@OptIn(ExperimentalForeignApi::class) | ||
internal actual fun basenameImpl(path: String): String { | ||
return __posix_basename(path)?.toKString() ?: "" | ||
} | ||
|
||
internal actual fun isAbsoluteImpl(path: String): Boolean = path.startsWith('/') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. | ||
*/ | ||
@file:OptIn(ExperimentalForeignApi::class) | ||
|
||
package kotlinx.io.files | ||
|
||
import kotlinx.cinterop.ExperimentalForeignApi | ||
import kotlinx.cinterop.cstr | ||
import kotlinx.cinterop.memScoped | ||
import kotlinx.cinterop.toKString | ||
import kotlinx.io.IOException | ||
import platform.Foundation.NSTemporaryDirectory | ||
import platform.posix.* | ||
|
||
|
||
internal actual fun atomicMoveImpl(source: Path, destination: Path) { | ||
if (rename(source.path, destination.path) != 0) { | ||
throw IOException("Move failed: ${strerror(errno)?.toKString()}") | ||
} | ||
} | ||
|
||
public actual val SystemTemporaryDirectory: Path | ||
get() = Path(NSTemporaryDirectory()) | ||
|
||
internal actual fun dirnameImpl(path: String): String { | ||
memScoped { | ||
return dirname(path.cstr.ptr)?.toKString() ?: "" | ||
} | ||
} | ||
|
||
internal actual fun basenameImpl(path: String): String { | ||
memScoped { | ||
return basename(path.cstr.ptr)?.toKString() ?: "" | ||
} | ||
} | ||
|
||
internal actual fun isAbsoluteImpl(path: String): Boolean = path.startsWith('/') | ||
|
||
internal actual fun mkdirImpl(path: String) { | ||
if (mkdir(path, PermissionAllowAll) != 0) { | ||
throw IOException("mkdir failed: ${strerror(errno)?.toKString()}") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.