* Handles processing for a deleted file. * Drops the corresponding data collection and deletes the index entry.
(db: Db, filepath: string)
| 316 | * Drops the corresponding data collection and deletes the index entry. |
| 317 | */ |
| 318 | async function _handleFileDeleted(db: Db, filepath: string): Promise<void> { |
| 319 | const collectionName = getCollectionNameFromJsonFile(filepath); // Get name from the path that was deleted |
| 320 | console.log(`\nProcessing Deletion for ${filepath} (Collection: ${collectionName || 'N/A'})...`); |
| 321 | |
| 322 | // 1. Drop the data collection (if applicable) |
| 323 | if (collectionName) { |
| 324 | try { |
| 325 | await db.collection(collectionName).drop(); |
| 326 | console.log(`Dropped collection '${collectionName}' due to file deletion.`); |
| 327 | } catch (err) { |
| 328 | if (!(err instanceof MongoServerError && err.codeName === 'NamespaceNotFound')) { |
| 329 | console.error(`Error dropping collection '${collectionName}' for deleted file:`, err); |
| 330 | } else { |
| 331 | console.log(`Collection '${collectionName}' not found, likely already dropped.`); |
| 332 | } |
| 333 | } |
| 334 | } else { |
| 335 | console.warn( |
| 336 | `Could not determine collection name for deleted file ${filepath}. Cannot drop collection.` |
| 337 | ); |
| 338 | } |
| 339 | |
| 340 | // 2. Update index collection |
| 341 | await updateIndexCollection(db, filepath, 'delete'); |
| 342 | } |
| 343 | |
| 344 | // --- Translation Helpers --- |
| 345 |
no test coverage detected