fix: properly handle critical file copy failures in initFiles

This commit is contained in:
xmk23333 2026-01-15 23:29:27 +08:00
parent 2cfcf8be66
commit a28f576d78

View File

@ -189,19 +189,14 @@ async function initFiles(): Promise<void> {
await cp(sourcePath, targetPath, { recursive: true, force: true })
} catch (error: unknown) {
const code = (error as NodeJS.ErrnoException).code
// EPERM/EBUSY: 文件被占用ENOENT: unlink 时目标不存在Windows cp force 模式的边界情况)
if (code === 'EPERM' || code === 'EBUSY' || code === 'ENOENT') {
await initLogger.warn(`Skipping ${file}: ${code}`)
// 如果目标文件已存在,跳过即可;否则尝试不带 force 复制
if (!existsSync(targetPath)) {
try {
await cp(sourcePath, targetPath, { recursive: true })
} catch {
await initLogger.warn(`Retry copy ${file} also failed`)
}
}
if (code === 'EPERM' || code === 'EBUSY') {
// 文件被占用,如果目标已存在则跳过
if (existsSync(targetPath)) {
await initLogger.warn(`Skipping ${file}: file is in use`)
return
}
}
// 其他错误或目标不存在时,向上抛出让 criticalFiles 检查处理
throw error
}
})