mirror of
https://github.com/GayPizzaSpecifications/dough.git
synced 2025-08-05 14:31:32 +00:00
dough-core and all of that
This commit is contained in:
@ -1,3 +1,13 @@
|
||||
plugins {
|
||||
dough_component
|
||||
}
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api(project(":dough-core"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
package gay.pizza.dough.fs
|
||||
|
||||
import gay.pizza.dough.core.time.UnixTime
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
import kotlinx.serialization.SerializationStrategy
|
||||
|
||||
interface FsOperations {
|
||||
fun exists(path: FsPath): Boolean
|
||||
|
||||
fun isDirectory(path: FsPath): Boolean
|
||||
fun isRegularFile(path: FsPath): Boolean
|
||||
fun isSymbolicLink(path: FsPath): Boolean
|
||||
@ -12,6 +14,8 @@ interface FsOperations {
|
||||
fun isWritable(path: FsPath): Boolean
|
||||
fun isExecutable(path: FsPath): Boolean
|
||||
|
||||
fun lastModified(path: FsPath): UnixTime
|
||||
|
||||
fun list(path: FsPath): Sequence<FsPath>
|
||||
|
||||
fun walk(path: FsPath): Sequence<FsPath>
|
||||
|
@ -0,0 +1,8 @@
|
||||
package gay.pizza.dough.fs
|
||||
|
||||
interface FsProvider {
|
||||
val currentWorkingDirectory: FsPath
|
||||
val operations: FsOperations
|
||||
|
||||
fun resolve(path: String): FsPath
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
package gay.pizza.dough.fs
|
||||
|
||||
expect fun FsPath(path: String): FsPath
|
||||
expect val PlatformFsProvider: FsProvider
|
||||
|
@ -1,5 +1,7 @@
|
||||
package gay.pizza.dough.fs
|
||||
|
||||
import gay.pizza.dough.core.time.UnixTime
|
||||
import gay.pizza.dough.core.toUnixTime
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
import kotlinx.serialization.SerializationStrategy
|
||||
import kotlinx.serialization.json.Json
|
||||
@ -11,6 +13,7 @@ import kotlin.streams.asSequence
|
||||
|
||||
object JavaFsOperations : FsOperations {
|
||||
override fun exists(path: FsPath): Boolean = Files.exists(path.toJavaPath())
|
||||
|
||||
override fun isDirectory(path: FsPath): Boolean = Files.isDirectory(path.toJavaPath())
|
||||
override fun isRegularFile(path: FsPath): Boolean = Files.isRegularFile(path.toJavaPath())
|
||||
override fun isSymbolicLink(path: FsPath): Boolean = Files.isSymbolicLink(path.toJavaPath())
|
||||
@ -18,10 +21,12 @@ object JavaFsOperations : FsOperations {
|
||||
override fun isWritable(path: FsPath): Boolean = Files.isWritable(path.toJavaPath())
|
||||
override fun isExecutable(path: FsPath): Boolean = Files.isExecutable(path.toJavaPath())
|
||||
|
||||
override fun lastModified(path: FsPath): UnixTime = Files.getLastModifiedTime(path.toJavaPath()).toUnixTime()
|
||||
|
||||
override fun list(path: FsPath): Sequence<FsPath> = Files.list(path.toJavaPath()).asSequence().map { it.toFsPath() }
|
||||
|
||||
override fun walk(path: FsPath): Sequence<FsPath> = Files.walk(path.toJavaPath()).asSequence().map { it.toFsPath() }
|
||||
override fun visit(path: FsPath, visitor: FsPathVisitor) =
|
||||
override fun visit(path: FsPath, visitor: FsPathVisitor): Unit =
|
||||
Files.walkFileTree(path.toJavaPath(), JavaFsPathVisitorAdapter(visitor)).run {}
|
||||
|
||||
override fun readString(path: FsPath): String = Files.readString(path.toJavaPath())
|
||||
|
@ -0,0 +1,14 @@
|
||||
package gay.pizza.dough.fs
|
||||
|
||||
import java.nio.file.FileSystem
|
||||
import kotlin.io.path.absolute
|
||||
|
||||
class JavaFsProvider(val fileSystem: FileSystem) : FsProvider {
|
||||
override val currentWorkingDirectory: FsPath
|
||||
get() = fileSystem.getPath(".").absolute().toFsPath()
|
||||
|
||||
override val operations: FsOperations = JavaFsOperations
|
||||
|
||||
override fun resolve(path: String): FsPath =
|
||||
fileSystem.getPath(path).toFsPath()
|
||||
}
|
@ -1,7 +1,5 @@
|
||||
package gay.pizza.dough.fs
|
||||
|
||||
import java.nio.file.Paths
|
||||
import java.nio.file.FileSystems
|
||||
|
||||
actual fun FsPath(path: String): FsPath {
|
||||
return JavaPath(Paths.get(path))
|
||||
}
|
||||
actual val PlatformFsProvider: FsProvider = JavaFsProvider(FileSystems.getDefault())
|
||||
|
Reference in New Issue
Block a user