mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-02-15 00:03:38 -07:00
Fix file lock not getting disposed when postamble throws an exception
This commit is contained in:
parent
a68df7a065
commit
bf76f10030
|
|
@ -34,13 +34,22 @@ public class ExportWrapperFixture : IDisposable
|
||||||
// Perform export only if it hasn't been done before
|
// Perform export only if it hasn't been done before
|
||||||
if (!File.Exists(filePath))
|
if (!File.Exists(filePath))
|
||||||
{
|
{
|
||||||
await new ExportChannelsCommand
|
try
|
||||||
{
|
{
|
||||||
Token = Secrets.DiscordToken,
|
await new ExportChannelsCommand
|
||||||
ChannelIds = new[] { channelId },
|
{
|
||||||
ExportFormat = format,
|
Token = Secrets.DiscordToken,
|
||||||
OutputPath = filePath
|
ChannelIds = new[] { channelId },
|
||||||
}.ExecuteAsync(new FakeConsole());
|
ExportFormat = format,
|
||||||
|
OutputPath = filePath
|
||||||
|
}.ExecuteAsync(new FakeConsole());
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// If the export fails, delete the file to prevent it from being used by tests
|
||||||
|
File.Delete(filePath);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return await File.ReadAllTextAsync(filePath);
|
return await File.ReadAllTextAsync(filePath);
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,16 @@ internal partial class MessageExporter : IAsyncDisposable
|
||||||
{
|
{
|
||||||
if (_writer is not null)
|
if (_writer is not null)
|
||||||
{
|
{
|
||||||
await _writer.WritePostambleAsync(cancellationToken);
|
try
|
||||||
await _writer.DisposeAsync();
|
{
|
||||||
_writer = null;
|
await _writer.WritePostambleAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
// Writer must be disposed, even if writing postamble fails
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
await _writer.DisposeAsync();
|
||||||
|
_writer = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,9 +67,7 @@ internal class HtmlMessageWriter : MessageWriter
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use <!--wmm:ignore--> to preserve blocks of code inside the templates
|
// Use <!--wmm:ignore--> to preserve blocks of code inside the templates
|
||||||
private string Minify(string html) => _minifier
|
private string Minify(string html) => _minifier.Minify(html, false).MinifiedContent;
|
||||||
.Minify(html, false)
|
|
||||||
.MinifiedContent;
|
|
||||||
|
|
||||||
public override async ValueTask WritePreambleAsync(
|
public override async ValueTask WritePreambleAsync(
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue