mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2026-02-10 19:50:28 +08:00
fix: properly handle critical file copy failures in initFiles
This commit is contained in:
parent
2cfcf8be66
commit
a28f576d78
@ -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
|
||||
}
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user