[System.IO.Compression] Remove the entry from ZipArchive entries when its deleted...
authorJoão Matos <joao@tritao.eu>
Thu, 4 Aug 2016 12:21:13 +0000 (13:21 +0100)
committerJoão Matos <joao@tritao.eu>
Thu, 4 Aug 2016 12:21:13 +0000 (13:21 +0100)
Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=43022.

mcs/class/System.IO.Compression/Test/System.IO.Compression/ZipTest.cs
mcs/class/System.IO.Compression/ZipArchive.cs
mcs/class/System.IO.Compression/ZipArchiveEntry.cs

index 2d03d559d4e08d402254d2a9d739f0c290484f35..f1b83746b47ccbb1ee5e2474abfee4dc16663a48 100644 (file)
@@ -182,6 +182,24 @@ namespace MonoTests.System.IO.Compression
                        File.Delete ("delete.zip");
                }
 
+               [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()
                {
index c1a3df57566020c08cf0509ddfc9f44c097dfe87..5df9434321ce2c8761255d6fad9ac38f977f8baf 100644 (file)
@@ -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)
index 9b415fbe6fd6a31487539a655c6a99bbe46b1644..0ea00c549def9016f0f17e144d805644641abab8 100644 (file)
@@ -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()