You've already forked linux-packaging-mono
Imported Upstream version 4.4.2.4
Former-commit-id: 92904c9c5915c37244316e42ba99e7b934ed7ee2
This commit is contained in:
parent
589d484eee
commit
0b4a830db1
@ -32,7 +32,7 @@ namespace System.IO.Compression
|
||||
internal class ZipArchiveEntryStream : Stream, IDisposable
|
||||
{
|
||||
private readonly ZipArchiveEntry entry;
|
||||
private readonly Stream stream;
|
||||
private Stream stream;
|
||||
|
||||
public override bool CanRead {
|
||||
get {
|
||||
@ -42,19 +42,19 @@ namespace System.IO.Compression
|
||||
|
||||
public override bool CanSeek {
|
||||
get {
|
||||
return stream.CanSeek;
|
||||
return entry.Archive.Mode != ZipArchiveMode.Read;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanWrite {
|
||||
get {
|
||||
return stream.CanWrite;
|
||||
return entry.Archive.Mode != ZipArchiveMode.Read;
|
||||
}
|
||||
}
|
||||
|
||||
public override long Length {
|
||||
get {
|
||||
return stream.Length;
|
||||
return stream.CanWrite ? stream.Length : entry.Length;
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,6 +98,34 @@ namespace System.IO.Compression
|
||||
stream.Write(buffer, offset, count);
|
||||
}
|
||||
|
||||
internal void EnsureWriteable()
|
||||
{
|
||||
if (entry.Archive.Mode == ZipArchiveMode.Update && !stream.CanWrite)
|
||||
{
|
||||
// Replace the read-only stream with a writeable memory stream.
|
||||
SetWriteable();
|
||||
}
|
||||
}
|
||||
|
||||
internal void SetWriteable()
|
||||
{
|
||||
var archive = entry.Archive;
|
||||
|
||||
var internalEntry = entry.entry;
|
||||
var newEntry = archive.CreateEntryInternal(internalEntry.Key);
|
||||
var newStream = newEntry.OpenEntryStream();
|
||||
|
||||
var openStream = stream;
|
||||
openStream.CopyTo(newStream);
|
||||
openStream.Dispose();
|
||||
|
||||
newStream.Position = 0;
|
||||
|
||||
archive.zipFile.RemoveEntry(internalEntry);
|
||||
entry.entry = newEntry;
|
||||
stream = newStream;
|
||||
}
|
||||
|
||||
public new void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
@ -117,8 +145,9 @@ namespace System.IO.Compression
|
||||
|
||||
public class ZipArchiveEntry
|
||||
{
|
||||
readonly SharpCompress.Archive.Zip.ZipArchiveEntry entry;
|
||||
internal SharpCompress.Archive.Zip.ZipArchiveEntry entry;
|
||||
internal ZipArchiveEntryStream openStream;
|
||||
internal bool wasWritten;
|
||||
private bool wasDeleted;
|
||||
|
||||
internal ZipArchiveEntry(ZipArchive archive, SharpCompress.Archive.Zip.ZipArchiveEntry entry)
|
||||
@ -174,7 +203,7 @@ namespace System.IO.Compression
|
||||
if (Archive.disposed)
|
||||
throw new ObjectDisposedException("The zip archive for this entry has been disposed.");
|
||||
|
||||
if (Archive.Mode != ZipArchiveMode.Update)
|
||||
if (Archive.Mode != ZipArchiveMode.Update)
|
||||
throw new NotSupportedException("The zip archive for this entry was opened in a mode other than Update.");
|
||||
|
||||
if (openStream != null)
|
||||
@ -198,9 +227,16 @@ namespace System.IO.Compression
|
||||
if (Archive.Mode == ZipArchiveMode.Create && openStream != null)
|
||||
throw new IOException("The archive for this entry was opened with the Create mode, and this entry has already been written to.");
|
||||
|
||||
openStream = new ZipArchiveEntryStream(this, entry.OpenEntryStream());
|
||||
var entryStream = entry.OpenEntryStream();
|
||||
openStream = new ZipArchiveEntryStream(this, entryStream);
|
||||
openStream.EnsureWriteable();
|
||||
|
||||
return openStream;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return FullName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user