Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoão Matos <joao@tritao.eu>2016-06-28 19:54:13 +0300
committerJoão Matos <joao@tritao.eu>2016-06-28 19:59:00 +0300
commitdab5ef4d6e864aef47c493131a4608d87b664c20 (patch)
tree38d95858abfaf5b5cdef2db64417ce2cef29cbd3 /mcs/class/System.IO.Compression
parent4a4d34f4894c541a9223d4ebf91692fd0966cef1 (diff)
[System.IO.Compression] Fixed writes to newly-created Zip archive entries in Update mode.
This regression was reported by RichardW of Open XML SDK project. Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=39282.
Diffstat (limited to 'mcs/class/System.IO.Compression')
-rw-r--r--mcs/class/System.IO.Compression/Test/System.IO.Compression/ZipTest.cs17
-rw-r--r--mcs/class/System.IO.Compression/ZipArchiveEntry.cs3
2 files changed, 19 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 d94a929e207..64b102c2d3d 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
@@ -341,6 +341,23 @@ namespace MonoTests.System.IO.Compression
}
[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()
{
File.Copy("archive.zip", "test.zip", overwrite: true);
diff --git a/mcs/class/System.IO.Compression/ZipArchiveEntry.cs b/mcs/class/System.IO.Compression/ZipArchiveEntry.cs
index 2b415eb5c8d..002b6f14ceb 100644
--- a/mcs/class/System.IO.Compression/ZipArchiveEntry.cs
+++ b/mcs/class/System.IO.Compression/ZipArchiveEntry.cs
@@ -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;
}