fix: symlink 探测有界并发 + UNC 标记平台中性化(回应 CR/自审)
- fs-tree: symlink 目标 stat 从串行改为 32 并发工作池(readdir 流关闭后统一 探测),symlink 密集/网络目标目录不再累加延迟;顺序与分类语义不变 - html-route: 解码不再重建反斜杠 UNC,统一重建为平台中性的 //server/share/... 前斜杠形态(win32/POSIX 均正确 resolve),从而删除 windowsPathStyle 平台信号 与 client isWindowsStylePath 助手;同时解决无 cwd 时正斜杠 UNC 的往返盲点 - 测试/文档同步;移除未使用的 isPosix
This commit is contained in:
+5
-21
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
import { encodeHtmlUrl } from '../html-route.ts'
|
||||
import type { BrowserProbeResult } from './browser.ts'
|
||||
import { isWindowsStylePath } from './paths.ts'
|
||||
|
||||
/** One wire failure. */
|
||||
export class SidebarApiError extends Error {
|
||||
@@ -212,29 +211,14 @@ function fileUrl(scope: SessionScope, path: string, download: boolean): string {
|
||||
return `/sidebar/file?${params.toString()}`
|
||||
}
|
||||
|
||||
/** A forward-slash UNC share (`//server/share/...`) — ambiguous with a POSIX
|
||||
* absolute path, so it only counts as Windows-style when the session cwd is
|
||||
* itself a forward-slash UNC (see htmlUrl). */
|
||||
function isForwardSlashUnc(path: string): boolean {
|
||||
return /^\/\/[^/]/.test(path)
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute URL of the HTML preview route (see html-route.ts): the path is
|
||||
* fully encoded so the previewed page's relative assets resolve back into
|
||||
* the same route with the session scope intact. The platform guard for the
|
||||
* UNC marker comes from the session cwd's shape (the browser OS may differ
|
||||
* from the host OS, so no client-side platform detection is used), extended
|
||||
* by the file path itself: an unambiguous backslash UNC path keeps its '//'
|
||||
* marker even while the cwd is still hydrating or arrives in forward-slash
|
||||
* form. A forward-slash `//` path is only marked when the cwd is itself a
|
||||
* forward-slash UNC — a POSIX session keeps `//server/share/...` as an
|
||||
* ordinary absolute path.
|
||||
* the same route with the session scope intact. The UNC marker is
|
||||
* platform-neutral — the host's requireAbsolute resolves the decoded
|
||||
* forward-slash `//server/share/...` form on both win32 and POSIX — so no
|
||||
* client-side platform signal is needed.
|
||||
*/
|
||||
export function htmlUrl(scope: SessionScope, path: string): string {
|
||||
const cwd = scope.cwd ?? ''
|
||||
const windowsPathStyle = isWindowsStylePath(cwd)
|
||||
|| isWindowsStylePath(path)
|
||||
|| (isForwardSlashUnc(path) && isForwardSlashUnc(cwd))
|
||||
return encodeHtmlUrl(scope.sessionId, path, windowsPathStyle)
|
||||
return encodeHtmlUrl(scope.sessionId, path)
|
||||
}
|
||||
|
||||
+2
-13
@@ -5,25 +5,14 @@
|
||||
* to '/' before comparison.
|
||||
*
|
||||
* This module is dependency-free (no node:path in the client bundle): the
|
||||
* host is the authority for path semantics, so these mirrors deliberately
|
||||
* accept a SUPERSET of absolute forms — anything a Windows host would emit
|
||||
* host is the authority for path semantics, so this mirror deliberately
|
||||
* accepts a SUPERSET of absolute forms — anything a Windows host would emit
|
||||
* (drive letters, UNC) plus POSIX roots. A form the host would reject
|
||||
* (e.g. a backslash UNC path on a POSIX host) passes through here and then
|
||||
* fails loudly in the host's requireAbsolute instead of being silently
|
||||
* joined onto the cwd.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Whether a path looks like it belongs to a Windows-style session: a drive
|
||||
* letter or any backslash (UNC shares, and drive paths in general).
|
||||
* Used as the platform signal for the html route's UNC marker — the client
|
||||
* cannot read process.platform (the browser OS may differ from the host),
|
||||
* but the session cwd shape is authoritative.
|
||||
*/
|
||||
export function isWindowsStylePath(path: string): boolean {
|
||||
return path.includes('\\') || /^[A-Za-z]:[\\/]/.test(path)
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirror of the host's absolute-path notion (see fs-tree.requireAbsolute):
|
||||
* POSIX roots, Windows drive letters, and Windows UNC network shares in
|
||||
|
||||
Reference in New Issue
Block a user