feat: 添加目录存在性检查并优化复制逻辑

- 添加目录存在性检查功能并更新复制逻辑以使用该功能
This commit is contained in:
2026-01-21 23:44:31 +08:00
parent fc916c7c1d
commit 96705e965d

View File

@@ -159,6 +159,9 @@ class FileSystemService extends Context.Tag('FileSystemService')<
readonly fileExists: ( readonly fileExists: (
filePath: string, filePath: string,
) => Effect.Effect<boolean, FileSystemError> ) => Effect.Effect<boolean, FileSystemError>
readonly dirExists: (
dirPath: string,
) => Effect.Effect<boolean, FileSystemError>
readonly copyFile: ( readonly copyFile: (
source: string, source: string,
target: 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) => copyFile: (source: string, target: string) =>
Effect.tryPromise({ Effect.tryPromise({
try: async () => { try: async () => {
@@ -381,7 +403,7 @@ const program = Effect.gen(function* () {
yield* Console.log('📦 开始复制二进制文件到 Tauri sidecar 目录...\n') yield* Console.log('📦 开始复制二进制文件到 Tauri sidecar 目录...\n')
// 1. 检查源目录 // 1. 检查源目录
const sourceExists = yield* fs.fileExists(config.sourceDir) const sourceExists = yield* fs.dirExists(config.sourceDir)
if (!sourceExists) { if (!sourceExists) {
yield* Console.error(`❌ 源目录不存在: ${config.sourceDir}`) yield* Console.error(`❌ 源目录不存在: ${config.sourceDir}`)
yield* Console.log( yield* Console.log(