{
key = key.Substring(1);
}
+ // .NET allows duplicate entries when saving and loading Zip files.
+ // The following lines are disabled from upstream SharpCompress to allow this.
+#if ZIP_ALLOW_DUPLICATE_KEYS
if (DoesKeyMatchExisting(key))
{
throw new ArchiveException("Cannot add entry with duplicate key: " + key);
}
+#endif
var entry = CreateEntry(key, source, size, modified, closeStream);
newEntries.Add(entry);
RebuildModifiedCollection();
{
p = p.Substring(1);
}
- return string.Equals(p, key, StringComparison.OrdinalIgnoreCase);
+ if (string.Equals(p, key, StringComparison.OrdinalIgnoreCase))
+ return true;
}
return false;
}
}
}
+ [Test]
+ public void ZipCreateDuplicateEntriesUpdateMode()
+ {
+ var stream = new MemoryStream();
+ using (var zipArchive = new ZipArchive(stream, ZipArchiveMode.Update, true))
+ {
+ var e2 = zipArchive.CreateEntry("BBB");
+ var e3 = zipArchive.CreateEntry("BBB");
+ }
+
+ stream.Position = 0;
+ using (var zipArchive = new ZipArchive(stream, ZipArchiveMode.Read))
+ {
+ Assert.AreEqual(2, zipArchive.Entries.Count);
+ }
+ }
+
[Test]
public void ZipWriteEntriesUpdateModeNonZeroPosition()
{
internal readonly ZipArchiveMode mode;
internal Encoding entryNameEncoding;
internal bool disposed;
- internal Dictionary<string, ZipArchiveEntry> entries;
+ internal List<ZipArchiveEntry> entries;
internal SharpCompress.Archive.Zip.ZipArchive zipFile;
public ZipArchive (Stream stream)
throw new InvalidDataException("The contents of the stream are not in the zip archive format.", e);
}
- entries = new Dictionary<string, ZipArchiveEntry>();
+ entries = new List<ZipArchiveEntry>();
if (Mode != ZipArchiveMode.Create) {
foreach (var entry in zipFile.Entries) {
var zipEntry = new ZipArchiveEntry(this, entry);
- entries[entry.Key] = zipEntry;
+ entries.Add(zipEntry);
}
}
}
if (entries == null)
return new ReadOnlyCollection<ZipArchiveEntry>(new List<ZipArchiveEntry>());
- return new ReadOnlyCollection<ZipArchiveEntry>(entries.Values.ToList());
+ return new ReadOnlyCollection<ZipArchiveEntry>(entries);
}
}
var internalEntry = CreateEntryInternal(entryName);
var archiveEntry = new ZipArchiveEntry(this, internalEntry);
- entries[entryName] = archiveEntry;
+ entries.Add(archiveEntry);
return archiveEntry;
}
if (zipFile == null)
throw new InvalidDataException("The zip archive is corrupt, and its entries cannot be retrieved.");
- return entries.ContainsKey(entryName) ? entries[entryName] : null;
+ return entries.FirstOrDefault(e => e.FullName == entryName);
}
private void Save()