mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2026-02-11 04:00:32 +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 })
|
await cp(sourcePath, targetPath, { recursive: true, force: true })
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const code = (error as NodeJS.ErrnoException).code
|
const code = (error as NodeJS.ErrnoException).code
|
||||||
// EPERM/EBUSY: 文件被占用;ENOENT: unlink 时目标不存在(Windows cp force 模式的边界情况)
|
if (code === 'EPERM' || code === 'EBUSY') {
|
||||||
if (code === 'EPERM' || code === 'EBUSY' || code === 'ENOENT') {
|
// 文件被占用,如果目标已存在则跳过
|
||||||
await initLogger.warn(`Skipping ${file}: ${code}`)
|
if (existsSync(targetPath)) {
|
||||||
// 如果目标文件已存在,跳过即可;否则尝试不带 force 复制
|
await initLogger.warn(`Skipping ${file}: file is in use`)
|
||||||
if (!existsSync(targetPath)) {
|
return
|
||||||
try {
|
|
||||||
await cp(sourcePath, targetPath, { recursive: true })
|
|
||||||
} catch {
|
|
||||||
await initLogger.warn(`Retry copy ${file} also failed`)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
// 其他错误或目标不存在时,向上抛出让 criticalFiles 检查处理
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user