Fixed issue where adding a new entry then removing it wouldn't actually remove it.

This commit is contained in:
Adam Hathcock
2013-12-20 12:28:17 +00:00
parent 84ed6bc7f0
commit 46fc663e90
6 changed files with 40 additions and 9 deletions

View File

@@ -213,6 +213,36 @@ namespace SharpCompress.Test
Directory.Delete(SCRATCH_FILES_PATH, true);
}
[TestMethod]
public void Zip_Create_New_Add_Remove()
{
base.ResetScratch();
foreach (var file in Directory.EnumerateFiles(ORIGINAL_FILES_PATH, "*.*", SearchOption.AllDirectories))
{
var newFileName = file.Substring(ORIGINAL_FILES_PATH.Length);
if (newFileName.StartsWith(Path.DirectorySeparatorChar.ToString()))
{
newFileName = newFileName.Substring(1);
}
newFileName = Path.Combine(SCRATCH_FILES_PATH, newFileName);
var newDir = Path.GetDirectoryName(newFileName);
if (!Directory.Exists(newDir))
{
Directory.CreateDirectory(newDir);
}
File.Copy(file, newFileName);
}
string scratchPath = Path.Combine(SCRATCH2_FILES_PATH, "Zip.deflate.noEmptyDirs.zip");
using (var archive = ZipArchive.Create())
{
archive.AddAllFromDirectory(SCRATCH_FILES_PATH);
archive.RemoveEntry(archive.Entries.Single(x => x.FilePath.EndsWith("jpg", StringComparison.OrdinalIgnoreCase)));
Assert.IsFalse(archive.Entries.Any(x => x.FilePath.EndsWith("jpg")));
}
Directory.Delete(SCRATCH_FILES_PATH, true);
}
[TestMethod]
public void Zip_Deflate_WinzipAES_Read()
{

View File

@@ -39,15 +39,15 @@ namespace SharpCompress.Archive
internal AbstractArchive(ArchiveType type, IEnumerable<Stream> streams, Options options)
{
this.Type = type;
Type = type;
lazyVolumes =
new LazyReadOnlyCollection<TVolume>(LoadVolumes(streams.Select<Stream, Stream>(CheckStreams), options));
new LazyReadOnlyCollection<TVolume>(LoadVolumes(streams.Select(CheckStreams), options));
lazyEntries = new LazyReadOnlyCollection<TEntry>(LoadEntries(Volumes));
}
internal AbstractArchive(ArchiveType type)
{
this.Type = type;
Type = type;
lazyVolumes = new LazyReadOnlyCollection<TVolume>(Enumerable.Empty<TVolume>());
lazyEntries = new LazyReadOnlyCollection<TEntry>(Enumerable.Empty<TEntry>());
}

View File

@@ -22,10 +22,10 @@ namespace SharpCompress.Archive
{
}
internal AbstractWritableArchive(ArchiveType type, IEnumerable<Stream> streams, Options options)
: base(type, streams, options)
internal AbstractWritableArchive(ArchiveType type, Stream stream, Options options)
: base(type, stream.AsEnumerable(), options)
{
if (streams.Any(x => !x.CanWrite))
if (!stream.CanWrite)
{
anyNotWritable = true;
}
@@ -61,6 +61,7 @@ namespace SharpCompress.Archive
private void RebuildModifiedCollection()
{
hasModifications = true;
newEntries.RemoveAll(v => removedEntries.Contains(v));
modifiedEntries.Clear();
modifiedEntries.AddRange(OldEntries.Concat(newEntries));
}

View File

@@ -147,7 +147,7 @@ namespace SharpCompress.Archive.GZip
/// <param name="stream"></param>
/// <param name="options"></param>
internal GZipArchive(Stream stream, Options options)
: base(ArchiveType.GZip, stream.AsEnumerable(), options)
: base(ArchiveType.GZip, stream, options)
{
}

View File

@@ -133,7 +133,7 @@ namespace SharpCompress.Archive.Tar
/// <param name="stream"></param>
/// <param name="options"></param>
internal TarArchive(Stream stream, Options options)
: base(ArchiveType.Tar, stream.AsEnumerable(), options)
: base(ArchiveType.Tar, stream, options)
{
}

View File

@@ -164,7 +164,7 @@ namespace SharpCompress.Archive.Zip
/// <param name="options"></param>
/// <param name="password"></param>
internal ZipArchive(Stream stream, Options options, string password = null)
: base(ArchiveType.Zip, stream.AsEnumerable(), options)
: base(ArchiveType.Zip, stream, options)
{
headerFactory = new SeekableZipHeaderFactory(password);
}