MCPcopy Index your code
hub / github.com/codeaashu/claude-code / cleanupOldMessageFiles

Function cleanupOldMessageFiles

src/utils/cleanup.ts:93–132  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

91}
92
93export async function cleanupOldMessageFiles(): Promise<CleanupResult> {
94 const fsImpl = getFsImplementation()
95 const cutoffDate = getCutoffDate()
96 const errorPath = CACHE_PATHS.errors()
97 const baseCachePath = CACHE_PATHS.baseLogs()
98
99 // Clean up message and error logs
100 let result = await cleanupOldFilesInDirectory(errorPath, cutoffDate, false)
101
102 // Clean up MCP logs
103 try {
104 let dirents
105 try {
106 dirents = await fsImpl.readdir(baseCachePath)
107 } catch {
108 return result
109 }
110
111 const mcpLogDirs = dirents
112 .filter(
113 dirent => dirent.isDirectory() && dirent.name.startsWith('mcp-logs-'),
114 )
115 .map(dirent => join(baseCachePath, dirent.name))
116
117 for (const mcpLogDir of mcpLogDirs) {
118 // Clean up files in MCP log directory
119 result = addCleanupResults(
120 result,
121 await cleanupOldFilesInDirectory(mcpLogDir, cutoffDate, true),
122 )
123 await tryRmdir(mcpLogDir, fsImpl)
124 }
125 } catch (error: unknown) {
126 if (error instanceof Error && 'code' in error && error.code !== 'ENOENT') {
127 logError(error)
128 }
129 }
130
131 return result
132}
133
134async function unlinkIfOld(
135 filePath: string,

Callers 1

Calls 6

getFsImplementationFunction · 0.85
getCutoffDateFunction · 0.85
addCleanupResultsFunction · 0.85
tryRmdirFunction · 0.85
logErrorFunction · 0.70

Tested by

no test coverage detected