Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
The by lazy were computed before customCwd as set by the korge gradle plugin
  • Loading branch information
soywiz committed Nov 28, 2020
1 parent ea726e4 commit 5b45583
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
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)]
}
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,23 @@ import com.soywiz.korio.process.posixExec
val tmpdir: String by lazy { Environment["TMPDIR"] ?: Environment["TEMP"] ?: Environment["TMP"] ?: "/tmp" }

var customCwd: String? = null
val cwd: String by lazy { customCwd ?: com.soywiz.korio.nativeCwd() }
val nativeCwd by lazy { com.soywiz.korio.nativeCwd() }
val cwd: String get() = customCwd ?: nativeCwd

actual val resourcesVfs: VfsFile by lazy { applicationDataVfs.jail() }
actual val rootLocalVfs: VfsFile by lazy { localVfs(cwd) }
actual val applicationVfs: VfsFile by lazy { localVfs(cwd) }
actual val applicationDataVfs: VfsFile by lazy { localVfs(cwd) }
val cwdVfs: VfsFile by lazy { DynamicRootVfs(rootLocalVfsNative) { cwd } }
actual val resourcesVfs: VfsFile by lazy { cwdVfs.jail() }
actual val cacheVfs: VfsFile by lazy { MemoryVfs() }
actual val externalStorageVfs: VfsFile by lazy { localVfs(cwd) }
actual val userHomeVfs: VfsFile by lazy { localVfs(cwd) }
actual val tempVfs: VfsFile by lazy { localVfs(tmpdir) }

actual fun localVfs(path: String): VfsFile = LocalVfsNative()[path]
actual val rootLocalVfs: VfsFile get() = cwdVfs
actual val applicationVfs: VfsFile get() = cwdVfs
actual val applicationDataVfs: VfsFile get() = cwdVfs
actual val externalStorageVfs: VfsFile get() = cwdVfs
actual val userHomeVfs: VfsFile get() = cwdVfs

val rootLocalVfsNative by lazy { LocalVfsNative() }

actual fun localVfs(path: String): VfsFile = rootLocalVfsNative[path]

private val IOWorker by lazy { Worker.start().also { kotlin.native.Platform.isMemoryLeakCheckerActive = false } }

Expand Down

0 comments on commit 5b45583

Please sign in to comment.