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

Function cleanupOldFilesInDirectory

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

Source from the content-addressed store, hash-verified

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