Remove temporary files after processing (#5456)

Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
Tobi Kremer
2023-06-21 12:47:34 +02:00
committed by GitHub
parent 8d69de1be0
commit a094087342

View File

@@ -40,6 +40,8 @@ export default abstract class ExportTask extends BaseTask<Props> {
},
});
let filePath: string | undefined;
try {
Logger.info("task", `ExportTask processing data for ${fileOperationId}`, {
includeAttachments: fileOperation.includeAttachments,
@@ -49,7 +51,7 @@ export default abstract class ExportTask extends BaseTask<Props> {
state: FileOperationState.Creating,
});
const filePath = await this.export(collections, fileOperation);
filePath = await this.export(collections, fileOperation);
Logger.info("task", `ExportTask uploading data for ${fileOperationId}`);
@@ -95,6 +97,12 @@ export default abstract class ExportTask extends BaseTask<Props> {
}).schedule();
}
throw error;
} finally {
if (filePath) {
void fs.promises.unlink(filePath).catch((error) => {
Logger.error(`Failed to delete temporary file ${filePath}`, error);
});
}
}
}