Fixed cleanup logic for temporary files

This commit is contained in:
Thorsten Sommer 2025-12-10 17:03:24 +01:00
parent 8e82a07a33
commit 3b6d55ca4c
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -25,10 +25,11 @@ public static class PandocExport
LOGGER.LogInformation($"The user chose the path '{response.SaveFilePath}' for the Microsoft Word export.");
var tempMarkdownFilePath = string.Empty;
try
{
var tempMarkdownFile = Guid.NewGuid().ToString();
var tempMarkdownFilePath = Path.Combine(Path.GetTempPath(), tempMarkdownFile);
tempMarkdownFilePath = Path.Combine(Path.GetTempPath(), tempMarkdownFile);
// Extract text content from chat:
var markdownText = markdownContent switch
@ -110,13 +111,16 @@ public static class PandocExport
finally
{
// Try to remove the temp file:
try
if (!string.IsNullOrWhiteSpace(tempMarkdownFilePath))
{
File.Delete(tempMarkdownFilePath);
}
catch
{
LOGGER.LogWarning($"Was not able to delete temporary file: '{tempMarkdownFilePath}'");
try
{
File.Delete(tempMarkdownFilePath);
}
catch
{
LOGGER.LogWarning($"Was not able to delete temporary file: '{tempMarkdownFilePath}'");
}
}
}
}