diff --git a/apps/desktop/copy.ts b/apps/desktop/copy.ts index c7c54c6..6420088 100644 --- a/apps/desktop/copy.ts +++ b/apps/desktop/copy.ts @@ -159,6 +159,9 @@ class FileSystemService extends Context.Tag('FileSystemService')< readonly fileExists: ( filePath: string, ) => Effect.Effect + readonly dirExists: ( + dirPath: string, + ) => Effect.Effect readonly copyFile: ( source: string, target: string, @@ -193,6 +196,25 @@ class FileSystemService extends Context.Tag('FileSystemService')< }), }), + dirExists: (dirPath: string) => + Effect.tryPromise({ + try: async () => { + const { default: fs } = await import('node:fs/promises') + try { + const stat = await fs.stat(dirPath) + return stat.isDirectory() + } catch { + return false + } + }, + catch: (cause: unknown) => + new FileSystemError({ + operation: 'dirExists', + path: dirPath, + cause, + }), + }), + copyFile: (source: string, target: string) => Effect.tryPromise({ try: async () => { @@ -381,7 +403,7 @@ const program = Effect.gen(function* () { yield* Console.log('📦 开始复制二进制文件到 Tauri sidecar 目录...\n') // 1. 检查源目录 - const sourceExists = yield* fs.fileExists(config.sourceDir) + const sourceExists = yield* fs.dirExists(config.sourceDir) if (!sourceExists) { yield* Console.error(`❌ 源目录不存在: ${config.sourceDir}`) yield* Console.log(