From 8c5498c3360b74741ebb18941857d82d41f6de9c Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 1 Nov 2025 00:05:15 +0000 Subject: [PATCH] Fix: Correct file exclusion logic in Compactor The file exclusion logic in the BuildWorkingFilesList method was flawed. The condition incorrectly included files for compression if their full path was present in the exclusion list, which is intended for file extensions. This change corrects the LINQ query to ensure that files are excluded based on their extension as intended. A new test project and test case have been added to verify this fix. --- .../CompactGUI.Core.Tests.csproj | 26 +++++++++++++ CompactGUI.Core.Tests/CompactorTests.cs | 38 +++++++++++++++++++ CompactGUI.Core/Compactor.cs | 2 +- 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 CompactGUI.Core.Tests/CompactGUI.Core.Tests.csproj create mode 100644 CompactGUI.Core.Tests/CompactorTests.cs diff --git a/CompactGUI.Core.Tests/CompactGUI.Core.Tests.csproj b/CompactGUI.Core.Tests/CompactGUI.Core.Tests.csproj new file mode 100644 index 0000000..2366154 --- /dev/null +++ b/CompactGUI.Core.Tests/CompactGUI.Core.Tests.csproj @@ -0,0 +1,26 @@ + + + + net9.0-windows + enable + false + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/CompactGUI.Core.Tests/CompactorTests.cs b/CompactGUI.Core.Tests/CompactorTests.cs new file mode 100644 index 0000000..0332a5f --- /dev/null +++ b/CompactGUI.Core.Tests/CompactorTests.cs @@ -0,0 +1,38 @@ +using Xunit; +using CompactGUI.Core; +using System.IO; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace CompactGUI.Core.Tests +{ + public class CompactorTests + { + [Fact] + public async Task BuildWorkingFilesList_WithExclusion_ShouldExcludeCorrectFiles() + { + // Arrange + var tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); + Directory.CreateDirectory(tempDir); + var file1 = Path.Combine(tempDir, "test.txt"); + var file2 = Path.Combine(tempDir, "test.log"); + File.WriteAllText(file1, "This is a test file."); + File.WriteAllText(file2, "This is a log file."); + + var analyser = new Analyser(tempDir, null); + var compactor = new Compactor(tempDir, WOFCompressionAlgorithm.XPRESS4K, new[] { ".log" }, analyser, null); + + // Act + var fileDetails = (FileDetails)await compactor.BuildWorkingFilesList(); + var workingFiles = new List(fileDetails); + + // Assert + Assert.Single(workingFiles); + Assert.Equal(file1, workingFiles[0].FileName); + + // Clean up + Directory.Delete(tempDir, true); + } + } +} diff --git a/CompactGUI.Core/Compactor.cs b/CompactGUI.Core/Compactor.cs index 0c6071f..d14627d 100644 --- a/CompactGUI.Core/Compactor.cs +++ b/CompactGUI.Core/Compactor.cs @@ -132,7 +132,7 @@ public async Task> BuildWorkingFilesList() .Where(fl => fl.CompressionMode != wofCompressionAlgorithm && fl.UncompressedSize > clusterSize - && ((fl.FileInfo != null && !excludedFileExtensions.Contains(fl.FileInfo.Extension)) || excludedFileExtensions.Contains(fl.FileName)) + && fl.FileInfo != null && !excludedFileExtensions.Contains(fl.FileInfo.Extension) ) .Select(fl => new FileDetails(fl.FileName, fl.UncompressedSize)) .ToList();