diff options
author | João Matos <joao@tritao.eu> | 2016-08-04 15:21:13 +0300 |
---|---|---|
committer | João Matos <joao@tritao.eu> | 2016-08-04 15:21:13 +0300 |
commit | 179e33d1006d8e9d95183cf6903ebe2b710cd0da (patch) | |
tree | 6a70abd9914cc91668ecb08d41db126c4f37aba2 /mcs/class/System.IO.Compression | |
parent | c0bd75d8cda542039cf325d1f7cb39214d7ce71e (diff) |
[System.IO.Compression] Remove the entry from ZipArchive entries when its deleted. Fixes #43022.
Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=43022.
Diffstat (limited to 'mcs/class/System.IO.Compression')
3 files changed, 25 insertions, 1 deletions
diff --git a/mcs/class/System.IO.Compression/Test/System.IO.Compression/ZipTest.cs b/mcs/class/System.IO.Compression/Test/System.IO.Compression/ZipTest.cs index 2d03d559d4e..f1b83746b47 100644 --- a/mcs/class/System.IO.Compression/Test/System.IO.Compression/ZipTest.cs +++ b/mcs/class/System.IO.Compression/Test/System.IO.Compression/ZipTest.cs @@ -183,6 +183,24 @@ namespace MonoTests.System.IO.Compression } [Test] + public void ZipDeleteEntryCheckEntries() + { + File.Copy("archive.zip", "delete.zip", overwrite: true); + using (var archive = new ZipArchive(File.Open("delete.zip", FileMode.Open), + ZipArchiveMode.Update)) + { + var entry = archive.GetEntry("foo.txt"); + Assert.IsNotNull(entry); + + entry.Delete(); + + Assert.IsNull(archive.Entries.FirstOrDefault(e => e == entry)); + } + + File.Delete ("delete.zip"); + } + + [Test] public void ZipGetEntryDeleteUpdateMode() { File.Copy("archive.zip", "delete.zip", overwrite: true); diff --git a/mcs/class/System.IO.Compression/ZipArchive.cs b/mcs/class/System.IO.Compression/ZipArchive.cs index c1a3df57566..5df9434321c 100644 --- a/mcs/class/System.IO.Compression/ZipArchive.cs +++ b/mcs/class/System.IO.Compression/ZipArchive.cs @@ -237,6 +237,12 @@ namespace System.IO.Compression } } + internal void RemoveEntryInternal(ZipArchiveEntry entry) + { + zipFile.RemoveEntry(entry.entry); + entries.Remove(entry); + } + protected virtual void Dispose (bool disposing) { if (disposed) diff --git a/mcs/class/System.IO.Compression/ZipArchiveEntry.cs b/mcs/class/System.IO.Compression/ZipArchiveEntry.cs index 9b415fbe6fd..0ea00c549de 100644 --- a/mcs/class/System.IO.Compression/ZipArchiveEntry.cs +++ b/mcs/class/System.IO.Compression/ZipArchiveEntry.cs @@ -210,7 +210,7 @@ namespace System.IO.Compression throw new IOException("The entry is already open for reading or writing."); wasDeleted = true; - Archive.zipFile.RemoveEntry(entry); + Archive.RemoveEntryInternal(this); } public Stream Open() |