From ccaabb7b1a89e1d1c0760ff656b888967bd45df4 Mon Sep 17 00:00:00 2001 From: xmk23333 Date: Thu, 15 Jan 2026 18:05:38 +0800 Subject: [PATCH] fix: sync updated geo files to profile work dir in lite mode --- src/main/core/factory.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/core/factory.ts b/src/main/core/factory.ts index 3c65027..dbf8ffa 100644 --- a/src/main/core/factory.ts +++ b/src/main/core/factory.ts @@ -1,4 +1,4 @@ -import { copyFile, mkdir, writeFile, readFile } from 'fs/promises' +import { copyFile, mkdir, writeFile, readFile, stat } from 'fs/promises' import vm from 'vm' import { existsSync, writeFileSync } from 'fs' import path from 'path' @@ -160,10 +160,23 @@ async function prepareProfileWorkDir(current: string | undefined): Promise if (!existsSync(mihomoProfileWorkDir(current))) { await mkdir(mihomoProfileWorkDir(current), { recursive: true }) } + + const isSourceNewer = async (sourcePath: string, targetPath: string): Promise => { + try { + const [sourceStats, targetStats] = await Promise.all([stat(sourcePath), stat(targetPath)]) + return sourceStats.mtime > targetStats.mtime + } catch { + return true + } + } + const copy = async (file: string): Promise => { const targetPath = path.join(mihomoProfileWorkDir(current), file) const sourcePath = path.join(mihomoWorkDir(), file) - if (!existsSync(targetPath) && existsSync(sourcePath)) { + if (!existsSync(sourcePath)) return + // 复制条件:目标不存在 或 源文件更新 + const shouldCopy = !existsSync(targetPath) || (await isSourceNewer(sourcePath, targetPath)) + if (shouldCopy) { await copyFile(sourcePath, targetPath) } }