From ad0a5c79326c30426b709029cf54d5c102432e96 Mon Sep 17 00:00:00 2001 From: pompurin404 Date: Sat, 12 Oct 2024 21:44:31 +0800 Subject: [PATCH] use copy instead of link --- src/main/config/profile.ts | 15 +-------------- src/main/core/factory.ts | 14 +++++++++----- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/main/config/profile.ts b/src/main/config/profile.ts index 45b64a8..5bf95b8 100644 --- a/src/main/config/profile.ts +++ b/src/main/config/profile.ts @@ -1,13 +1,12 @@ import { getControledMihomoConfig } from './controledMihomo' import { mihomoProfileWorkDir, profileConfigPath, profilePath } from '../utils/dirs' import { addProfileUpdater } from '../core/profileUpdater' -import { readFile, rm, unlink, writeFile } from 'fs/promises' +import { readFile, rm, writeFile } from 'fs/promises' import { restartCore } from '../core/manager' import { getAppConfig } from './app' import { existsSync } from 'fs' import axios, { AxiosResponse } from 'axios' import yaml from 'yaml' -import path from 'path' import { defaultProfile } from '../utils/template' import { subStorePort } from '../resolve/server' @@ -94,18 +93,6 @@ export async function removeProfileItem(id: string): Promise { await restartCore() } if (existsSync(mihomoProfileWorkDir(id))) { - const unln = async (file: string): Promise => { - const targetPath = path.join(mihomoProfileWorkDir(id), file) - if (existsSync(targetPath)) { - await unlink(targetPath) - } - } - await Promise.all([ - unln('country.mmdb'), - unln('geoip.dat'), - unln('geosite.dat'), - unln('ASN.mmdb') - ]) await rm(mihomoProfileWorkDir(id), { recursive: true }) } } diff --git a/src/main/core/factory.ts b/src/main/core/factory.ts index c3ee8cb..75ce60e 100644 --- a/src/main/core/factory.ts +++ b/src/main/core/factory.ts @@ -15,7 +15,7 @@ import { overridePath } from '../utils/dirs' import yaml from 'yaml' -import { link, mkdir, writeFile } from 'fs/promises' +import { copyFile, mkdir, writeFile } from 'fs/promises' import { deepMerge } from '../utils/merge' import vm from 'vm' import { existsSync, writeFileSync } from 'fs' @@ -47,15 +47,19 @@ async function prepareProfileWorkDir(current: string | undefined): Promise if (!existsSync(mihomoProfileWorkDir(current))) { await mkdir(mihomoProfileWorkDir(current), { recursive: true }) } - const ln = async (file: string): Promise => { + const copy = async (file: string): Promise => { const targetPath = path.join(mihomoProfileWorkDir(current), file) - const sourcePath = path.join(mihomoWorkDir(), file) if (!existsSync(targetPath) && existsSync(sourcePath)) { - await link(sourcePath, targetPath) + await copyFile(sourcePath, targetPath) } } - await Promise.all([ln('country.mmdb'), ln('geoip.dat'), ln('geosite.dat'), ln('ASN.mmdb')]) + await Promise.all([ + copy('country.mmdb'), + copy('geoip.dat'), + copy('geosite.dat'), + copy('ASN.mmdb') + ]) } async function overrideProfile(