This repository has been archived by the owner on Jul 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The by lazy were computed before customCwd as set by the korge gradle plugin
- Loading branch information
Showing
3 changed files
with
41 additions
and
8 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
korio/src/commonMain/kotlin/com/soywiz/korio/file/std/DynamicRootVfs.kt
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,11 @@ | ||
package com.soywiz.korio.file.std | ||
|
||
import com.soywiz.korio.file.* | ||
|
||
fun DynamicRootVfs(base: Vfs, rootGet: () -> String) = DynamicRootVfsVfs(base, rootGet).root | ||
|
||
class DynamicRootVfsVfs(val base: Vfs, val rootGet: () -> String) : Vfs.Proxy() { | ||
private fun getLocalAbsolutePath(path: String) = rootGet().pathInfo.lightCombine(path.pathInfo).fullPath | ||
override fun getAbsolutePath(path: String): String = base.getAbsolutePath(getLocalAbsolutePath(path)) | ||
override suspend fun access(path: String): VfsFile = base[getLocalAbsolutePath(path)] | ||
} |
17 changes: 17 additions & 0 deletions
17
korio/src/commonTest/kotlin/com/soywiz/korio/file/std/DynamicRootVfsTest.kt
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,17 @@ | ||
package com.soywiz.korio.file.std | ||
|
||
import com.soywiz.korio.async.* | ||
import kotlin.test.* | ||
|
||
class DynamicRootVfsTest { | ||
@Test | ||
fun test() = suspendTest { | ||
val memoryVfs = MemoryVfsMix("path0/demo" to "world") | ||
var base = "/path0" | ||
val root = DynamicRootVfs(memoryVfs.vfs) { base } | ||
assertEquals("/path0/demo", root["demo"].absolutePath) | ||
assertEquals("world", root["demo"].readString()) | ||
base = "/path1" | ||
assertEquals("/path1/test", root["test"].absolutePath) | ||
} | ||
} |
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