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,6 +111,8 @@ public static class PandocExport
finally
{
// Try to remove the temp file:
if (!string.IsNullOrWhiteSpace(tempMarkdownFilePath))
{
try
{
File.Delete(tempMarkdownFilePath);
@ -120,4 +123,5 @@ public static class PandocExport
}
}
}
}
}