fix: 修复 WSL 会话 Linux 路径解析 (#399)

This commit is contained in:
Kunping Wang
2026-09-02 23:20:17 +08:00
committed by Menghuan1918
parent dde0923980
commit 180b16de1b
4 changed files with 94 additions and 5 deletions
+5 -4
View File
@@ -2,6 +2,7 @@
import { realpath } from 'node:fs/promises'
import { basename, dirname, join } from 'node:path'
import { isWithin, requireAbsolute } from './fs-tree.ts'
import { resolveSessionPath } from './session-path.ts'
import { SidebarError } from './wire.ts'
/** Resolve a path and convert filesystem resolution failures to an API error. */
@@ -25,14 +26,14 @@ function assertWithinWorkspace(workspace: string, target: string): void {
* enforce containment.
*
* @param cwd - Session workspace directory.
* @param target - Client-supplied absolute path.
* @param target - Client-supplied absolute path in the session's namespace.
* @param fence - Whether containment is enforced (the settings-page
* `workspaceFence` switch). Even when false the paths are still resolved
* through symlinks so callers always receive the canonical target.
* @returns The canonical absolute path used for the filesystem operation.
*/
export async function ensureWorkspacePath(cwd: string, target: string, fence = true): Promise<string> {
const absolute = requireAbsolute(target)
const absolute = requireAbsolute(resolveSessionPath(cwd, target))
const [realCwd, realTarget] = await Promise.all([
resolveRealPath(cwd, 'workspace'),
resolveRealPath(absolute, 'target'),
@@ -49,13 +50,13 @@ export async function ensureWorkspacePath(cwd: string, target: string, fence = t
* symlink is never left in the path passed to the write operation.
*
* @param cwd - Session workspace directory.
* @param target - Client-supplied absolute destination path.
* @param target - Client-supplied absolute destination path in the session's namespace.
* @param fence - Whether containment is enforced (the settings-page
* `workspaceFence` switch). Resolution/canonicalization is identical either way.
* @returns A canonical path for an existing target or its nearest existing ancestor.
*/
export async function ensureWorkspaceWritePath(cwd: string, target: string, fence = true): Promise<string> {
const absolute = requireAbsolute(target)
const absolute = requireAbsolute(resolveSessionPath(cwd, target))
const realCwd = await resolveRealPath(cwd, 'workspace')
let existingPath = absolute
const missingSegments: string[] = []