Skip to content

Commit 886d477

Browse files
committed
ZipNameTransform TrimPrefix not correctly updated via property fixed.
Minor test updates. ZipFile now honors UseZip64 setting when updating an existing archive.
1 parent 710dc5b commit 886d477

File tree

6 files changed

+61
-17
lines changed

6 files changed

+61
-17
lines changed

mkDistribution.bat

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@echo mkDistribution v1.0"
1+
@echo "mkDistribution v1.1"
22

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

2121
@echo todo generate documentation and the rest of the distribution image.
22-
samples\cs\bin\sz -rc SharpZipLib.zip current\*.dll
22+
samples\cs\bin\sz -rc current\SharpZipLib.zip current\*.dll
23+
24+
mkdir current\source
25+
copy doc\readme.rtf current\source
26+
copy doc\Changes.txt current\source
27+
copy doc\Copying.txt current\source
28+
rem copy doc\SharpZipLib.chm current\source
29+
copy *.bat current\source
30+
copy *.build current\source
31+
32+
2333
REM Compress source to SharpZipLib_SourceSamples.zip
2434
REM Build CHM file
2535
REM Build Bin Zip files

src/Zip/ZipEntry.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,8 @@ internal void ProcessExtraData(bool localHeader)
878878
else {
879879
if (
880880
((versionToExtract & 0xff) >= ZipConstants.VersionZip64) &&
881-
( (size == uint.MaxValue) ||
882-
(compressedSize == uint.MaxValue) )) {
881+
((size == uint.MaxValue) || (compressedSize == uint.MaxValue))
882+
) {
883883
throw new ZipException("Zip64 Extended information required but is missing.");
884884
}
885885
}

src/Zip/ZipFile.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,14 +1805,14 @@ int WriteCentralDirectoryHeader(ZipEntry entry)
18051805
WriteLEInt((int)entry.Crc);
18061806
}
18071807

1808-
if ( entry.CompressedSize >= 0xffffffff ) {
1808+
if ( (entry.IsZip64Forced()) || (entry.CompressedSize >= 0xffffffff) ) {
18091809
WriteLEInt(-1);
18101810
}
18111811
else {
18121812
WriteLEInt((int)(entry.CompressedSize & 0xffffffff));
18131813
}
18141814

1815-
if ( entry.Size >= 0xffffffff ) {
1815+
if ( (entry.IsZip64Forced()) || (entry.Size >= 0xffffffff) ) {
18161816
WriteLEInt(-1);
18171817
}
18181818
else {
@@ -2422,6 +2422,8 @@ void RunUpdates()
24222422
else
24232423
{
24242424
workFile = ZipFile.Create(archiveStorage_.GetTemporaryOutput());
2425+
workFile.UseZip64 = UseZip64;
2426+
24252427
if (key != null) {
24262428
workFile.key = (byte[])key.Clone();
24272429
}

src/Zip/ZipNameTransform.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ public ZipNameTransform()
6262
/// <param name="trimPrefix">The string to trim from front of paths if found.</param>
6363
public ZipNameTransform(string trimPrefix)
6464
{
65-
if ( trimPrefix != null ) {
66-
trimPrefix_ = trimPrefix.ToLower();
67-
}
65+
TrimPrefix = trimPrefix;
6866
}
6967
#endregion
7068

@@ -116,7 +114,7 @@ public string TransformDirectory(string name)
116114
}
117115

118116
/// <summary>
119-
/// Transform a file name according to the Zip file naming conventions.
117+
/// Transform a windows file name according to the Zip file naming conventions.
120118
/// </summary>
121119
/// <param name="name">The file name to transform.</param>
122120
/// <returns>The transformed name.</returns>
@@ -127,7 +125,8 @@ public string TransformFile(string name)
127125
if ( (trimPrefix_ != null) && (lowerName.IndexOf(trimPrefix_) == 0) ) {
128126
name = name.Substring(trimPrefix_.Length);
129127
}
130-
128+
129+
// The following can throw exceptions when the name contains invalid characters
131130
if (Path.IsPathRooted(name) == true) {
132131
// NOTE:
133132
// for UNC names... \\machine\share\zoom\beet.txt gives \zoom\beet.txt
@@ -149,10 +148,17 @@ public string TransformFile(string name)
149148
/// <summary>
150149
/// Get/set the path prefix to be trimmed from paths if present.
151150
/// </summary>
151+
/// <remarks>The prefix is trimmed before any conversion from
152+
/// a windows path is done.</remarks>
152153
public string TrimPrefix
153154
{
154155
get { return trimPrefix_; }
155-
set { trimPrefix_ = value; }
156+
set {
157+
trimPrefix_ = value;
158+
if (trimPrefix_ != null) {
159+
trimPrefix_ = trimPrefix_.ToLower();
160+
}
161+
}
156162
}
157163

158164
/// <summary>

tests/Base/InflaterDeflaterTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public void SmallBlocks()
165165
}
166166

167167
[Test]
168+
[Explicit]
168169
[Category("Base")]
169170
[Category("ExcludeFromAutoBuild")]
170171
public void FindBug()

tests/Zip/ZipTests.cs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ public class ExerciseZipEntry : ZipBase
451451
{
452452
void PiecewiseCompare(ZipEntry lhs, ZipEntry rhs)
453453
{
454-
// Introspection might be better here?
454+
// Introspection would be better here of course
455455
Assert.AreEqual(lhs.Name, rhs.Name, "Cloned name mismatch" );
456456
Assert.AreEqual(lhs.Crc, rhs.Crc, "Cloned crc mismatch" );
457457
Assert.AreEqual(lhs.Comment, rhs.Comment, "Cloned comment mismatch" );
@@ -2039,15 +2039,31 @@ public void ReadOverrunShort()
20392039
[TestFixture]
20402040
public class ExerciseZipNameTransform : ZipBase
20412041
{
2042+
void TestFile(ZipNameTransform t, string original, string expected)
2043+
{
2044+
string transformed = t.TransformFile(original);
2045+
Assert.AreEqual(expected, transformed, "Should be equal");
2046+
}
2047+
20422048
[Test]
20432049
[Category("Zip")]
20442050
public void Exercise()
20452051
{
2046-
ZipNameTransform nt = new ZipNameTransform();
2052+
ZipNameTransform t = new ZipNameTransform();
2053+
2054+
TestFile(t, "abcdef", "abcdef");
2055+
TestFile(t, @"\\uncpath\d1\file1", "file1");
2056+
TestFile(t, @"C:\absolute\file2", "absolute/file2");
2057+
2058+
// This is ignored but could be converted to 'file3'
2059+
TestFile(t, @"./file3", "./file3");
20472060

2048-
string original = "abcdefghijklmnopqrstuvwxyz";
2049-
string transformed = nt.TransformFile(original);
2050-
Assert.AreEqual(original, transformed, "Should be equal");
2061+
// The following relative paths cant be handled and are ignored
2062+
TestFile(t, @"../file3", "../file3");
2063+
TestFile(t, @".../file3", ".../file3");
2064+
2065+
// Trick filenames.
2066+
TestFile(t, @".....file3", ".....file3");
20512067
}
20522068
}
20532069
[TestFixture]
@@ -2348,6 +2364,15 @@ public void Zip64Useage()
23482364
}
23492365
}
23502366

2367+
[Test]
2368+
[Category("Zip")]
2369+
[Explicit]
2370+
public void Zip64Offset()
2371+
{
2372+
// TODO: Test to check that a zip64 offset value is loaded correctly.
2373+
// Changes in ZipEntry to CentralHeaderRequiresZip64 and LocalHeaderRequiresZip64
2374+
// were not quite correct...
2375+
}
23512376

23522377
[Test]
23532378
[Category("Zip")]

0 commit comments

Comments
 (0)