Skip to content

Commit

Permalink
ZipNameTransform TrimPrefix not correctly updated via property fixed.
Browse files Browse the repository at this point in the history
Minor test updates.
ZipFile now honors UseZip64 setting when updating an existing archive.
  • Loading branch information
jfreilly committed Jun 18, 2007
1 parent 710dc5b commit 886d477
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 17 deletions.
14 changes: 12 additions & 2 deletions mkDistribution.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@echo mkDistribution v1.0"
@echo "mkDistribution v1.1"

if exist current (
rmdir /s /q current
Expand All @@ -19,7 +19,17 @@ mkdir current\net-20
nant -t:net-2.0 -D:build.output.dir=current\net-20 -buildfile:sharpZLib.build build

@echo todo generate documentation and the rest of the distribution image.
samples\cs\bin\sz -rc SharpZipLib.zip current\*.dll
samples\cs\bin\sz -rc current\SharpZipLib.zip current\*.dll

mkdir current\source
copy doc\readme.rtf current\source
copy doc\Changes.txt current\source
copy doc\Copying.txt current\source
rem copy doc\SharpZipLib.chm current\source
copy *.bat current\source
copy *.build current\source


REM Compress source to SharpZipLib_SourceSamples.zip
REM Build CHM file
REM Build Bin Zip files
4 changes: 2 additions & 2 deletions src/Zip/ZipEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -878,8 +878,8 @@ internal void ProcessExtraData(bool localHeader)
else {
if (
((versionToExtract & 0xff) >= ZipConstants.VersionZip64) &&
( (size == uint.MaxValue) ||
(compressedSize == uint.MaxValue) )) {
((size == uint.MaxValue) || (compressedSize == uint.MaxValue))
) {
throw new ZipException("Zip64 Extended information required but is missing.");
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/Zip/ZipFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1805,14 +1805,14 @@ int WriteCentralDirectoryHeader(ZipEntry entry)
WriteLEInt((int)entry.Crc);
}

if ( entry.CompressedSize >= 0xffffffff ) {
if ( (entry.IsZip64Forced()) || (entry.CompressedSize >= 0xffffffff) ) {
WriteLEInt(-1);
}
else {
WriteLEInt((int)(entry.CompressedSize & 0xffffffff));
}

if ( entry.Size >= 0xffffffff ) {
if ( (entry.IsZip64Forced()) || (entry.Size >= 0xffffffff) ) {
WriteLEInt(-1);
}
else {
Expand Down Expand Up @@ -2422,6 +2422,8 @@ void RunUpdates()
else
{
workFile = ZipFile.Create(archiveStorage_.GetTemporaryOutput());
workFile.UseZip64 = UseZip64;

if (key != null) {
workFile.key = (byte[])key.Clone();
}
Expand Down
18 changes: 12 additions & 6 deletions src/Zip/ZipNameTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public ZipNameTransform()
/// <param name="trimPrefix">The string to trim from front of paths if found.</param>
public ZipNameTransform(string trimPrefix)
{
if ( trimPrefix != null ) {
trimPrefix_ = trimPrefix.ToLower();
}
TrimPrefix = trimPrefix;
}
#endregion

Expand Down Expand Up @@ -116,7 +114,7 @@ public string TransformDirectory(string name)
}

/// <summary>
/// Transform a file name according to the Zip file naming conventions.
/// Transform a windows file name according to the Zip file naming conventions.
/// </summary>
/// <param name="name">The file name to transform.</param>
/// <returns>The transformed name.</returns>
Expand All @@ -127,7 +125,8 @@ public string TransformFile(string name)
if ( (trimPrefix_ != null) && (lowerName.IndexOf(trimPrefix_) == 0) ) {
name = name.Substring(trimPrefix_.Length);
}


// The following can throw exceptions when the name contains invalid characters
if (Path.IsPathRooted(name) == true) {
// NOTE:
// for UNC names... \\machine\share\zoom\beet.txt gives \zoom\beet.txt
Expand All @@ -149,10 +148,17 @@ public string TransformFile(string name)
/// <summary>
/// Get/set the path prefix to be trimmed from paths if present.
/// </summary>
/// <remarks>The prefix is trimmed before any conversion from
/// a windows path is done.</remarks>
public string TrimPrefix
{
get { return trimPrefix_; }
set { trimPrefix_ = value; }
set {
trimPrefix_ = value;
if (trimPrefix_ != null) {
trimPrefix_ = trimPrefix_.ToLower();
}
}
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions tests/Base/InflaterDeflaterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public void SmallBlocks()
}

[Test]
[Explicit]
[Category("Base")]
[Category("ExcludeFromAutoBuild")]
public void FindBug()
Expand Down
35 changes: 30 additions & 5 deletions tests/Zip/ZipTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ public class ExerciseZipEntry : ZipBase
{
void PiecewiseCompare(ZipEntry lhs, ZipEntry rhs)
{
// Introspection might be better here?
// Introspection would be better here of course
Assert.AreEqual(lhs.Name, rhs.Name, "Cloned name mismatch" );
Assert.AreEqual(lhs.Crc, rhs.Crc, "Cloned crc mismatch" );
Assert.AreEqual(lhs.Comment, rhs.Comment, "Cloned comment mismatch" );
Expand Down Expand Up @@ -2039,15 +2039,31 @@ public void ReadOverrunShort()
[TestFixture]
public class ExerciseZipNameTransform : ZipBase
{
void TestFile(ZipNameTransform t, string original, string expected)
{
string transformed = t.TransformFile(original);
Assert.AreEqual(expected, transformed, "Should be equal");
}

[Test]
[Category("Zip")]
public void Exercise()
{
ZipNameTransform nt = new ZipNameTransform();
ZipNameTransform t = new ZipNameTransform();

TestFile(t, "abcdef", "abcdef");
TestFile(t, @"\\uncpath\d1\file1", "file1");
TestFile(t, @"C:\absolute\file2", "absolute/file2");

// This is ignored but could be converted to 'file3'
TestFile(t, @"./file3", "./file3");

string original = "abcdefghijklmnopqrstuvwxyz";
string transformed = nt.TransformFile(original);
Assert.AreEqual(original, transformed, "Should be equal");
// The following relative paths cant be handled and are ignored
TestFile(t, @"../file3", "../file3");
TestFile(t, @".../file3", ".../file3");

// Trick filenames.
TestFile(t, @".....file3", ".....file3");
}
}
[TestFixture]
Expand Down Expand Up @@ -2348,6 +2364,15 @@ public void Zip64Useage()
}
}

[Test]
[Category("Zip")]
[Explicit]
public void Zip64Offset()
{
// TODO: Test to check that a zip64 offset value is loaded correctly.
// Changes in ZipEntry to CentralHeaderRequiresZip64 and LocalHeaderRequiresZip64
// were not quite correct...
}

[Test]
[Category("Zip")]
Expand Down

0 comments on commit 886d477

Please sign in to comment.