Compare commits

...

2 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
dd242cb1c5 Fix ExtractToDirectory to properly truncate existing files
Changed File.OpenWrite to File.Create to ensure files are truncated when extracting over existing files. File.OpenWrite does not truncate, leaving old data at the end if the new file is shorter.

Added test Zip_Deflate_ArchiveExtractToDirectory_Overwrite to verify the fix.

Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
2025-11-14 08:54:45 +00:00
copilot-swe-agent[bot]
0ecbe02ede Initial plan 2025-11-14 08:35:27 +00:00
2 changed files with 23 additions and 1 deletions

View File

@@ -74,7 +74,7 @@ public static class IArchiveExtensions
}
// Write file
using var fs = File.OpenWrite(path);
using var fs = File.Create(path);
entry.WriteTo(fs);
// Update progress

View File

@@ -92,6 +92,28 @@ public class ZipArchiveTests : ArchiveTests
public void Zip_Deflate_ArchiveExtractToDirectory() =>
ArchiveExtractToDirectory("Zip.deflate.zip");
[Fact]
public void Zip_Deflate_ArchiveExtractToDirectory_Overwrite()
{
// First extraction
ArchiveExtractToDirectory("Zip.deflate.zip");
// Corrupt one of the extracted files by making it longer
var testFile = Path.Combine(SCRATCH_FILES_PATH, "Tar.tar");
if (File.Exists(testFile))
{
var originalSize = new FileInfo(testFile).Length;
File.WriteAllText(testFile, new string('X', (int)originalSize + 1000));
Assert.True(new FileInfo(testFile).Length > originalSize);
}
// Second extraction should overwrite and produce correct file sizes
ArchiveExtractToDirectory("Zip.deflate.zip");
// Verify files are correct size (not corrupted with leftover data)
VerifyFiles();
}
//will detect and load other files
[Fact]
public void Zip_Deflate_Multi_ArchiveFirstFileRead() =>