From f56c5858188f3f81c5647d3f331a0d7c5eaf629b Mon Sep 17 00:00:00 2001 From: ezequielnick <107352853+ezequielnick@users.noreply.github.com> Date: Sat, 9 Aug 2025 10:05:09 +0800 Subject: [PATCH] refactor: copy geodata only if source files are newer --- src/main/utils/init.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/utils/init.ts b/src/main/utils/init.ts index fc50bfe..af1a0e2 100644 --- a/src/main/utils/init.ts +++ b/src/main/utils/init.ts @@ -82,6 +82,18 @@ async function fixDataDirPermissions(): Promise { } } + // 比较修改geodata文件修改时间 +async function isSourceNewer(sourcePath: string, targetPath: string): Promise { + try { + const sourceStats = await stat(sourcePath) + const targetStats = await stat(targetPath) + + return sourceStats.mtime > targetStats.mtime + } catch { + return true + } +} + async function initDirs(): Promise { await fixDataDirPermissions() @@ -137,11 +149,18 @@ async function initFiles(): Promise { const sourcePath = path.join(resourcesFilesDir(), file) try { - if (!existsSync(targetPath) && existsSync(sourcePath)) { - await cp(sourcePath, targetPath, { recursive: true }) + // 检查是否需要复制 + if (existsSync(sourcePath)) { + const shouldCopyToWork = !existsSync(targetPath) || await isSourceNewer(sourcePath, targetPath) + if (shouldCopyToWork) { + await cp(sourcePath, targetPath, { recursive: true }) + } } - if (!existsSync(testTargetPath) && existsSync(sourcePath)) { - await cp(sourcePath, testTargetPath, { recursive: true }) + if (existsSync(sourcePath)) { + const shouldCopyToTest = !existsSync(testTargetPath) || await isSourceNewer(sourcePath, testTargetPath) + if (shouldCopyToTest) { + await cp(sourcePath, testTargetPath, { recursive: true }) + } } } catch (error) { console.error(`Failed to copy ${file}:`, error)