MCPcopy Create free account
hub / github.com/Noumena-Network/code / cleanupLegacyCache

Function cleanupLegacyCache

src/utils/plugins/installedPluginsManager.ts:194–247  ·  view source on GitHub ↗

* Clean up legacy non-versioned cache directories. * * Legacy cache structure: ~/.claude/plugins/cache/{plugin-name}/ * Versioned cache structure: ~/.ncode/plugins/cache/{marketplace}/{plugin}/{version}/ * * This function removes legacy directories that are not referenced by any installation.

(v2Data: InstalledPluginsFileV2)

Source from the content-addressed store, hash-verified

192 * This function removes legacy directories that are not referenced by any installation.
193 */
194function cleanupLegacyCache(v2Data: InstalledPluginsFileV2): void {
195 const fs = getFsImplementation()
196 const cachePath = getPluginCachePath()
197 try {
198 // Collect all install paths that are referenced
199 const referencedPaths = new Set<string>()
200 for (const installations of Object.values(v2Data.plugins)) {
201 for (const entry of installations) {
202 referencedPaths.add(entry.installPath)
203 }
204 }
205
206 // List top-level directories in cache
207 const entries = fs.readdirSync(cachePath)
208
209 for (const dirent of entries) {
210 if (!dirent.isDirectory()) {
211 continue
212 }
213
214 const entry = dirent.name
215 const entryPath = join(cachePath, entry)
216
217 // Check if this is a versioned cache (marketplace dir with plugin/version subdirs)
218 // or a legacy cache (flat plugin directory)
219 const subEntries = fs.readdirSync(entryPath)
220 const hasVersionedStructure = subEntries.some(subDirent => {
221 if (!subDirent.isDirectory()) return false
222 const subPath = join(entryPath, subDirent.name)
223 // Check if subdir contains version directories (semver-like or hash)
224 const versionEntries = fs.readdirSync(subPath)
225 return versionEntries.some(vDirent => vDirent.isDirectory())
226 })
227
228 if (hasVersionedStructure) {
229 // This is a marketplace directory with versioned structure - skip
230 continue
231 }
232
233 // This is a legacy flat cache directory
234 // Check if it's referenced by any installation
235 if (!referencedPaths.has(entryPath)) {
236 // Not referenced - safe to delete
237 fs.rmSync(entryPath, { recursive: true, force: true })
238 logForDebugging(`Cleaned up legacy cache directory: ${entry}`)
239 }
240 }
241 } catch (error) {
242 const errorMsg = errorMessage(error)
243 logForDebugging(`Failed to clean up legacy cache: ${errorMsg}`, {
244 level: 'warn',
245 })
246 }
247}
248
249/**
250 * Reset migration state (for testing)

Callers 1

Calls 6

getFsImplementationFunction · 0.85
getPluginCachePathFunction · 0.85
logForDebuggingFunction · 0.50
errorMessageFunction · 0.50
addMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected