Remove temporary files after processing (#5456)
Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user