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

Function cleanupOldImageCaches

src/utils/imageStore.ts:129–167  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

127 * Clean up old image cache directories from previous sessions.
128 */
129export async function cleanupOldImageCaches(): Promise<void> {
130 const fsImpl = getFsImplementation()
131 const baseDir = join(getClaudeConfigHomeDir(), IMAGE_STORE_DIR)
132 const currentSessionId = getSessionId()
133
134 try {
135 let sessionDirs
136 try {
137 sessionDirs = await fsImpl.readdir(baseDir)
138 } catch {
139 return
140 }
141
142 for (const sessionDir of sessionDirs) {
143 if (sessionDir.name === currentSessionId) {
144 continue
145 }
146
147 const sessionPath = join(baseDir, sessionDir.name)
148 try {
149 await fsImpl.rm(sessionPath, { recursive: true, force: true })
150 logForDebugging(`Cleaned up old image cache: ${sessionPath}`)
151 } catch {
152 // Ignore errors for individual directories
153 }
154 }
155
156 try {
157 const remaining = await fsImpl.readdir(baseDir)
158 if (remaining.length === 0) {
159 await fsImpl.rmdir(baseDir)
160 }
161 } catch {
162 // Ignore
163 }
164 } catch {
165 // Ignore errors reading base directory
166 }
167}
168

Callers 1

Calls 3

getFsImplementationFunction · 0.85
getSessionIdFunction · 0.85
logForDebuggingFunction · 0.85

Tested by

no test coverage detected