[System.IO.Compression] Fixed writes to newly-created Zip archive entries in Update...
authorJoão Matos <joao@tritao.eu>
Tue, 28 Jun 2016 16:54:13 +0000 (17:54 +0100)
committerJoão Matos <joao@tritao.eu>
Tue, 28 Jun 2016 16:59:00 +0000 (17:59 +0100)
This regression was reported by RichardW of Open XML SDK project.

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=39282.

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

index d94a929e207d75b01b8bf94ce2dd7c6ec30000d5..64b102c2d3dd6b5f062b9869e08b341634ee1e69 100644 (file)
@@ -340,6 +340,23 @@ namespace MonoTests.System.IO.Compression
                        File.Delete ("test.zip");
                }
 
+               [Test]
+               public void ZipWriteEntriesUpdateModeNewEntry()
+               {
+                       var stream = new MemoryStream();
+                       var zipArchive = new ZipArchive(stream, ZipArchiveMode.Update);
+
+                       var newEntry = zipArchive.CreateEntry("testEntry");
+
+                       using (var newStream = newEntry.Open())
+                       {
+                               using (var sw = new StreamWriter(newStream))
+                               {
+                                       sw.Write("TEST");
+                               }
+                       }
+               }
+
                [Test]
                public void ZipWriteEntriesUpdateModeNonZeroPosition()
                {
index 2b415eb5c8da2993e874371260e73d1cc4694858..002b6f14cebf24b891867403223f977f7c3b6b5f 100644 (file)
@@ -98,7 +98,8 @@ namespace System.IO.Compression
                        if (entry.Archive.Mode == ZipArchiveMode.Update && !entry.wasWritten)
                        {
                                // Replace the read-only stream with a writeable memory stream.
-                               SetWriteable();
+                               if (!stream.CanWrite)
+                                   SetWriteable();
                                entry.wasWritten = true;
                        }