diff --git a/DiscordChatExporter.Cli.Tests/Infra/ExportWrapper.cs b/DiscordChatExporter.Cli.Tests/Infra/ExportWrapper.cs index af7a8ed8..d4776c4c 100644 --- a/DiscordChatExporter.Cli.Tests/Infra/ExportWrapper.cs +++ b/DiscordChatExporter.Cli.Tests/Infra/ExportWrapper.cs @@ -20,7 +20,7 @@ namespace DiscordChatExporter.Cli.Tests.Infra; public static class ExportWrapper { - private static readonly ConcurrentDictionary Locks = new(); + private static readonly ConcurrentDictionary Locks = new(StringComparer.Ordinal); private static readonly string DirPath = Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? Directory.GetCurrentDirectory(), @@ -42,15 +42,15 @@ public static class ExportWrapper private static async ValueTask ExportAsync(Snowflake channelId, ExportFormat format) { + var fileName = channelId.ToString() + '.' + format.GetFileExtension(); + var filePath = Path.Combine(DirPath, fileName); + // Lock separately for each channel and format - var channelLock = Locks.GetOrAdd($"{channelId}_{format}", _ => new SemaphoreSlim(1, 1)); + var channelLock = Locks.GetOrAdd(filePath, _ => new SemaphoreSlim(1, 1)); await channelLock.WaitAsync(); try { - var fileName = channelId.ToString() + '.' + format.GetFileExtension(); - var filePath = Path.Combine(DirPath, fileName); - // Perform export only if it hasn't been done before if (!File.Exists(filePath)) {