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

Function cleanupOldMessageFiles

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

Source from the content-addressed store, hash-verified

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