diff options
author | nea <romangraef@gmail.com> | 2021-08-11 00:36:09 +0200 |
---|---|---|
committer | nea <romangraef@gmail.com> | 2021-08-11 00:36:09 +0200 |
commit | ef5d0429c059dad87147b7f1468bf288228aedbb (patch) | |
tree | d57c4f6a84f47a9c7fae4fcf9c5b3cd83b1acd28 /src/main/kotlin/WebOS.kt | |
parent | 87f1eb3dc6c03a1369a71523a526c861efc25b80 (diff) | |
download | webos-ef5d0429c059dad87147b7f1468bf288228aedbb.tar.gz webos-ef5d0429c059dad87147b7f1468bf288228aedbb.tar.bz2 webos-ef5d0429c059dad87147b7f1468bf288228aedbb.zip |
STOPSHIP nea geht schlafen
Diffstat (limited to 'src/main/kotlin/WebOS.kt')
-rw-r--r-- | src/main/kotlin/WebOS.kt | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/main/kotlin/WebOS.kt b/src/main/kotlin/WebOS.kt index 2ff0b62..d1b0d81 100644 --- a/src/main/kotlin/WebOS.kt +++ b/src/main/kotlin/WebOS.kt @@ -58,7 +58,62 @@ class Console(val os: WebOS, val renderElement: Element?) { class WebOS { private val _consoles = mutableListOf<Console>() val consoles get() = _consoles.toList() + val fileSystem = FileSystem() fun registerConsole(element: Element) { _consoles.add(Console(this, element)) } } + +interface User { + val name: String + val homeDirectory: Path +} + +data class Path private constructor(val parts: List<String>) { + companion object { + fun of(text: String) = + Path(text.split("/")) + fun of(vararg parts: String): Path { + if(parts.any { it.contains("/") }) + throw IllegalArgumentException("Path parts cannot contain forward slashes") + return Path(parts.toList()) + } + } +} + +class FileSystem { + val mounts = mutableMapOf<Path, Mount>() + fun mount(path: Path, mount:Mount) { + mounts[path] = mount + } + fun <T>findMountFor(path: Path, operation: Mount.(relativePath: Path) -> T) :T{ + val (mountPath, mount) = mounts.filterKeys { + // path.startsWith(it) + true + }.maxByOrNull { it.key.parts.size} ?: throw IllegalStateException("No mount present") + return mount.operation(mountPath.relativize(path)) + } + + fun read(path: Path): ReadResult = findMountFor(path) { read(it) } + fun write(path: Path, data: ByteArray): Unit = TODO() + fun stat(path: Path): Unit = TODO() +} + +sealed class ReadResult { + class Success(val text: String) : ReadResult() + object NotFound + object NoAccess +} +interface Mount { + fun read(relativePath: Path): ReadResult = TODO() + fun write(path: Path, data: ByteArray): Unit = TODO() + fun stat(path: Path): Unit = TODO() +} + +data class Stat( + val exists: Boolean, + var owner: User, + val created: Long, + val edited: Long, + val size: Long +) |