diff --git a/src/main/utils/init.ts b/src/main/utils/init.ts index f2866e3..0b9eb52 100644 --- a/src/main/utils/init.ts +++ b/src/main/utils/init.ts @@ -189,19 +189,14 @@ async function initFiles(): Promise { 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 } - return } + // 其他错误或目标不存在时,向上抛出让 criticalFiles 检查处理 throw error } })