Skip to content

Commit

Permalink
🐛 [kmp] 修复realpath异常
Browse files Browse the repository at this point in the history
  • Loading branch information
kingsword09 committed May 13, 2024
1 parent 7179d84 commit 186b444
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion next/kmp/app/desktopApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ kotlin {
}
}

val appVersion = "3.5.0602"
val appVersion = "3.5.1300"

compose.desktop {
application {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class DownloadNMM : NativeMicroModule("download.browser.dweb", "Download") {
controller.downloadFactory(downloadTask)
}
/// TODO 使用新版的 模块文件系统替代 realPath,比如 file:///$mmid/{$downloadTask.filepath}
downloadTask.filepath = realPath(downloadTask.filepath)
downloadTask.filepath = realPath(downloadTask.filepath).toString()
downloadTask.toJsonElement()
},
// 开始/恢复 下载
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class JmmNMM : NativeMicroModule("jmm.browser.dweb", "Js MicroModule Service") {

/// 提供JsMicroModule的文件适配器
/// file:///usr/*
val appsDir = realPath("/data/apps").toPath()
val appsDir = realPath("/data/apps")
val usr = object : IVirtualFsDirectory {
override fun isMatch(firstSegment: String) = firstSegment == "usr"
override val fs: FileSystem = SystemFileSystem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ class ZipNMM : NativeMicroModule("zip.browser.dweb", "Zip") {
val sourcePath = realPath(request.query("sourcePath"))
val targetPath = realPath(request.query("targetPath"))
// 先解压到一个临时目录
val tmpVfsPath = "/data/tmp/${targetPath.substring(targetPath.lastIndexOf("/") + 1)}"
val tmpVfsPath = "/data/tmp/${targetPath.name}"
// 获取真实目录
val tmpPath = realPath(tmpVfsPath)
// 开始解压
val ok = decompress(sourcePath, tmpPath)
val ok = decompress(sourcePath.toString(), tmpPath.toString())
if (!ok) {
return@defineBooleanResponse false
}
return@defineBooleanResponse moveFile(tmpVfsPath, targetPath)
return@defineBooleanResponse moveFile(tmpVfsPath, targetPath.toString())
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,14 @@ class FileNMM : NativeMicroModule("file.std.dweb", "File Manager") {
"/remove" bind PureMethod.DELETE by defineBooleanResponse {
val (filepath, fs) = getPath()
val recursive = request.queryAsOrNull<Boolean>("recursive") ?: false
if (recursive) {
fs.deleteRecursively(filepath, false)
} else {
fs.delete(filepath, false)
}
true
runCatching {
if (recursive) {
fs.deleteRecursively(filepath, false)
} else {
fs.delete(filepath, false)
}
true
}.getOrElse { false }
},
"/move" bind PureMethod.GET by defineBooleanResponse {
val (sourcePath, sourceFs) = getPath("sourcePath")
Expand Down Expand Up @@ -418,7 +420,7 @@ class VirtualFsPath(
}
}
private val virtualFirstSegment = virtualFullPath.segments.first()
private val virtualFirstPath = "/$virtualFirstSegment".toPath()
private val virtualFirstPath = "${virtualFullPath.root?:"/"}$virtualFirstSegment".toPath()
private val virtualContentPath = virtualFullPath.relativeTo(virtualFirstPath)

private val vfsDirectory = findVfsDirectory(virtualFirstSegment) ?: throw ResponseException(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.dweb_browser.core.std.file.ext

import okio.Path.Companion.toPath
import org.dweb_browser.core.module.MicroModule
import org.dweb_browser.core.std.dns.nativeFetch
import org.dweb_browser.pure.http.IPureBody
Expand Down Expand Up @@ -40,7 +41,7 @@ suspend fun MicroModule.Runtime.pickFile(path: String) =

suspend fun MicroModule.Runtime.realPath(path: String) = nativeFetch(
"file://file.std.dweb/realPath?path=$path"
).text()
).text().toPath()

suspend fun MicroModule.Runtime.appendFile(path: String, body: IPureBody) {
nativeFetch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class DWebViewEngine internal constructor(
userDataDirectoryLocks.withLock(remoteMM.mmid) {
userDataDirectoryInUseMicroModuleSet.getOrPut(remoteMM.mmid) {
remoteMM.createDir("/data/dwebview")
remoteMM.realPath("/data/dwebview").toPath()
remoteMM.realPath("/data/dwebview")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.dweb_browser.platform.desktop.webview.WebviewEngine
class DesktopLocationObserver(override val mm: MicroModule.Runtime) : LocationObserver() {
companion object {
val browser = SuspendOnce1 { mm: MicroModule.Runtime ->
WebviewEngine.offScreen(mm.realPath("/data/sys-location").toPath().toNioPath()).newBrowser()
WebviewEngine.offScreen(mm.realPath("/data/sys-location").toNioPath()).newBrowser()
}
val getWebGeolocation = SuspendOnce1 { mm: MicroModule.Runtime ->
mm.createDir("/data/sys-location")
Expand Down

0 comments on commit 186b444

Please sign in to comment.