Permalink
Browse files

Merge PR #295: Fix ZipEntry name mismatch when attempting to delete a…

… directory entry
  • Loading branch information...
benleedom authored and piksel committed Jan 3, 2019
1 parent 45347c3 commit 02694653b396edd3fbd1815d1507b57441f59f3a
@@ -2461,7 +2461,9 @@ private void CopyEntryDataDirect(ZipUpdate update, Stream stream, bool updateCrc
private int FindExistingUpdate(ZipEntry entry)
{
int result = -1;
string convertedName = GetTransformedFileName(entry.Name);
string convertedName = entry.IsDirectory
? GetTransformedDirectoryName(entry.Name)
: GetTransformedFileName(entry.Name);

if (updateIndex_.ContainsKey(convertedName))
{
@@ -403,24 +403,36 @@ public void AddAndDeleteEntries()
string addFile2 = Path.Combine(tempFile, "b.dat");
MakeTempFile(addFile2, 259);

string addDirectory = Path.Combine(tempFile, "dir");

tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");

using (ZipFile f = ZipFile.Create(tempFile))
{
f.BeginUpdate();
f.Add(addFile);
f.Add(addFile2);
f.AddDirectory(addDirectory);
f.CommitUpdate();
Assert.IsTrue(f.TestArchive(true));
}

using (ZipFile f = new ZipFile(tempFile))
{
Assert.AreEqual(2, f.Count);
Assert.AreEqual(3, f.Count);
Assert.IsTrue(f.TestArchive(true));

// Delete file
f.BeginUpdate();
f.Delete(f[0]);
f.CommitUpdate();
Assert.AreEqual(2, f.Count);
Assert.IsTrue(f.TestArchive(true));

// Delete directory
f.BeginUpdate();
f.Delete(f[1]);
f.CommitUpdate();
Assert.AreEqual(1, f.Count);
Assert.IsTrue(f.TestArchive(true));
}

0 comments on commit 0269465

Please sign in to comment.