From 5947394338d11429d3d93ae8493b2e7981b0bae1 Mon Sep 17 00:00:00 2001 From: xmk23333 Date: Thu, 15 Jan 2026 18:00:04 +0800 Subject: [PATCH] fix: avoid ENOENT/EPERM errors when copying init files --- src/main/utils/init.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/utils/init.ts b/src/main/utils/init.ts index c6cd681..bfe4f32 100644 --- a/src/main/utils/init.ts +++ b/src/main/utils/init.ts @@ -187,7 +187,18 @@ async function initFiles(): Promise { targets.map(async (targetPath) => { const shouldCopy = !existsSync(targetPath) || (await isSourceNewer(sourcePath, targetPath)) if (shouldCopy) { - await cp(sourcePath, targetPath, { recursive: true, force: true }) + // 先删除目标,force: true 会忽略 ENOENT,避免 cp 内部 unlink 的问题 + try { + await rm(targetPath, { recursive: true, force: true }) + } catch (error: unknown) { + // EPERM: 文件被占用,跳过本次复制 + if ((error as NodeJS.ErrnoException).code === 'EPERM') { + await initLogger.warn(`Skipping ${file}: file is in use`) + return + } + throw error + } + await cp(sourcePath, targetPath, { recursive: true }) } }) )