From 42e8a5b4dfac4644367078bd8fef1cf7a8992297 Mon Sep 17 00:00:00 2001 From: puzhen <1303385763@qq.com> Date: Tue, 21 Oct 2025 20:07:14 +0100 Subject: [PATCH] chore: clean cache --- electron/main/install-deps.ts | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/electron/main/install-deps.ts b/electron/main/install-deps.ts index c475ab94b..257fca38e 100644 --- a/electron/main/install-deps.ts +++ b/electron/main/install-deps.ts @@ -6,6 +6,7 @@ import fs from 'node:fs' import { getBackendPath, getBinaryPath, getCachePath, getVenvPath, cleanupOldVenvs, isBinaryExists, runInstallScript } from './utils/process' import { spawn } from 'child_process' import { safeMainWindowSend } from './utils/safeWebContentsSend' +import os from 'node:os' const userData = app.getPath('userData'); const versionFile = path.join(userData, 'version.txt'); @@ -57,6 +58,13 @@ Promise => { return new Promise(async (resolve, reject) => { try { + // Clean up cache in production environment BEFORE any checks + // This ensures users always get fresh dependencies in production + if (app.isPackaged) { + log.info('[CACHE CLEANUP] Production environment detected, cleaning cache before dependency check...'); + cleanupCacheInProduction(); + } + const versionExists:boolean = checkInstallOperations.getSavedVersion(); // Check if command tools are installed @@ -280,6 +288,34 @@ class InstallLogs { } } +/** + * Clean up cache directory + * This ensures users get fresh dependencies + * Note: Only call this in production environment (caller should check app.isPackaged) + */ +function cleanupCacheInProduction(): void { + try { + const cacheBaseDir = path.join(os.homedir(), '.eigent', 'cache'); + + if (!fs.existsSync(cacheBaseDir)) { + log.info('[CACHE CLEANUP] Cache directory does not exist, nothing to clean'); + return; + } + + log.info('[CACHE CLEANUP] Cleaning cache directory:', cacheBaseDir); + + fs.rmSync(cacheBaseDir, { recursive: true, force: true }); + + log.info('[CACHE CLEANUP] Cache directory cleaned successfully'); + + fs.mkdirSync(cacheBaseDir, { recursive: true }); + log.info('[CACHE CLEANUP] Empty cache directory recreated'); + + } catch (error) { + log.error('[CACHE CLEANUP] Failed to clean cache directory:', error); + } +} + const runInstall = (extraArgs: string[], version: string) => { const installLogs = new InstallLogs(extraArgs, version); return new Promise((resolveInner, rejectInner) => {