From 6ab5290cfbb9f33f4d4a083dcb5f9fa084bb52d2 Mon Sep 17 00:00:00 2001 From: Research Assistant Date: Wed, 13 May 2026 19:17:12 +0800 Subject: [PATCH] fix(plugin): check model cache integrity not just directory existence --- paperforge/plugin/main.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/paperforge/plugin/main.js b/paperforge/plugin/main.js index 061a0de3..47d538ac 100644 --- a/paperforge/plugin/main.js +++ b/paperforge/plugin/main.js @@ -2967,8 +2967,23 @@ class PaperForgeSettingTab extends PluginSettingTab { const cacheName = 'models--' + model.replace('/', '--'); const fs = require('fs'); const os = require('os'); - const cachePath = os.homedir() + '/.cache/huggingface/hub/' + cacheName; - const isCached = fs.existsSync(cachePath); + const path = require('path'); + const cachePath = path.join(os.homedir(), '.cache', 'huggingface', 'hub', cacheName); + + // Check integrity: directory exists AND has snapshots with files + let isCached = false; + if (fs.existsSync(cachePath)) { + const snapDir = path.join(cachePath, 'snapshots'); + if (fs.existsSync(snapDir)) { + try { + const entries = fs.readdirSync(snapDir); + isCached = entries.some(e => { + const p = path.join(snapDir, e); + return fs.statSync(p).isDirectory() && fs.readdirSync(p).length > 0; + }); + } catch (_) {} + } + } if (isCached) { button.setButtonText('Uninstall').setWarning();