🐛 fix(vscode): 接管时把会话文件里的发送方路径重写为本机路径
Claude-Session: https://claude.ai/code/session_011cEyL6k351U2BzX1Qmygph
This commit is contained in:
1 parent
07c40897e2
commit
71a91fe7ec
7 files changed
+151
-10
No files matched your search
@@ -120,3 +120,35 @@ export async function installCodexSession(relPath: string, srcFile: string, code
|
||||
await fsp.mkdir(path.dirname(dst), { recursive: true })
|
||||
await fsp.copyFile(srcFile, dst)
|
||||
}
|
||||
|
||||
/**
|
||||
* 迁移会话里发送方的 worktree 路径重写成接收方的路径。
|
||||
* split/join 而非正则替换——路径里的 `.` `(` 等字符不用转义,出现次数就是替换次数。
|
||||
*/
|
||||
export async function rewritePathInFile(file: string, from: string, to: string): Promise<number> {
|
||||
const content = await fsp.readFile(file, 'utf8')
|
||||
const parts = content.split(from)
|
||||
const count = parts.length - 1
|
||||
if (count > 0)
|
||||
await fsp.writeFile(file, parts.join(to))
|
||||
return count
|
||||
}
|
||||
|
||||
export async function rewritePathInTree(dir: string, from: string, to: string): Promise<number> {
|
||||
let entries: Array<{ name: string, isDirectory: () => boolean, isFile: () => boolean }>
|
||||
try {
|
||||
entries = await fsp.readdir(dir, { withFileTypes: true })
|
||||
}
|
||||
catch {
|
||||
return 0
|
||||
}
|
||||
let total = 0
|
||||
for (const entry of entries) {
|
||||
const full = path.join(dir, entry.name)
|
||||
if (entry.isDirectory())
|
||||
total += await rewritePathInTree(full, from, to)
|
||||
else if (entry.isFile())
|
||||
total += await rewritePathInFile(full, from, to)
|
||||
}
|
||||
return total
|
||||
}
|
||||
Reference in new issue
Block a user