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

Function cleanupOldFilesInDirectory

src/utils/cleanup.ts:55–91  ·  view source on GitHub ↗
(
  dirPath: string,
  cutoffDate: Date,
  isMessagePath: boolean,
)

Source from the content-addressed store, hash-verified

53}
54
55async function cleanupOldFilesInDirectory(
56 dirPath: string,
57 cutoffDate: Date,
58 isMessagePath: boolean,
59): Promise<CleanupResult> {
60 const result: CleanupResult = { messages: 0, errors: 0 }
61
62 try {
63 const files = await getFsImplementation().readdir(dirPath)
64
65 for (const file of files) {
66 try {
67 // Convert filename format where all ':.' were replaced with '-'
68 const timestamp = convertFileNameToDate(file.name)
69 if (timestamp < cutoffDate) {
70 await getFsImplementation().unlink(join(dirPath, file.name))
71 // Increment the appropriate counter
72 if (isMessagePath) {
73 result.messages++
74 } else {
75 result.errors++
76 }
77 }
78 } catch (error) {
79 // Log but continue processing other files
80 logError(error as Error)
81 }
82 }
83 } catch (error: unknown) {
84 // Ignore if directory doesn't exist
85 if (error instanceof Error && 'code' in error && error.code !== 'ENOENT') {
86 logError(error)
87 }
88 }
89
90 return result
91}
92
93export async function cleanupOldMessageFiles(): Promise<CleanupResult> {
94 const fsImpl = getFsImplementation()

Callers 1

cleanupOldMessageFilesFunction · 0.85

Calls 3

getFsImplementationFunction · 0.85
convertFileNameToDateFunction · 0.85
logErrorFunction · 0.70

Tested by

no test coverage detected