Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Z-1684 Fixed File Timestamp being lost via ZipFile.Add with modified …

…entryname
  • Loading branch information...
commit 5f57a54eeca2a6c1a13265ead38249c795bc6718 1 parent 9322513
@davidpierson davidpierson authored
View
12 src/Zip/IEntryFactory.cs
@@ -35,6 +35,9 @@
// obligated to do so. If you do not wish to do so, delete this
// exception statement from your version.
+// HISTORY
+// 2012-11-29 Z-1684 Added MakeFileEntry(string fileName, string entryName, bool useFileSystem)
+
using ICSharpCode.SharpZipLib.Core;
namespace ICSharpCode.SharpZipLib.Zip
@@ -60,6 +63,15 @@ public interface IEntryFactory
ZipEntry MakeFileEntry(string fileName, bool useFileSystem);
/// <summary>
+ /// Create a <see cref="ZipEntry"/> for a file given its actual name and optional override name
+ /// </summary>
+ /// <param name="fileName">The name of the file to create an entry for.</param>
+ /// <param name="entryName">An alternative name to be used for the new entry. Null if not applicable.</param>
+ /// <param name="useFileSystem">If true get details from the file system if the file exists.</param>
+ /// <returns>Returns a <see cref="ZipEntry">file entry</see> based on the <paramref name="fileName"/> passed.</returns>
+ ZipEntry MakeFileEntry(string fileName, string entryName, bool useFileSystem);
+
+ /// <summary>
/// Create a <see cref="ZipEntry"/> for a directory given its name
/// </summary>
/// <param name="directoryName">The name of the directory to create an entry for.</param>
View
20 src/Zip/ZipEntryFactory.cs
@@ -35,6 +35,9 @@
// obligated to do so. If you do not wish to do so, delete this
// exception statement from your version.
+// HISTORY
+// 2012-11-29 Z-1684 Added MakeFileEntry(string fileName, string entryName, bool useFileSystem)
+
using System;
using System.IO;
@@ -207,18 +210,29 @@ public bool IsUnicodeText
/// <returns>Returns a new <see cref="ZipEntry"/> based on the <paramref name="fileName"/>.</returns>
public ZipEntry MakeFileEntry(string fileName)
{
- return MakeFileEntry(fileName, true);
+ return MakeFileEntry(fileName, null, true);
+ }
+
+ /// <summary>
+ /// Make a new <see cref="ZipEntry"/> for a file.
+ /// </summary>
+ /// <param name="fileName">The name of the file to create a new entry for.</param>
+ /// <param name="useFileSystem">If true entry detail is retrieved from the file system if the file exists.</param>
+ /// <returns>Returns a new <see cref="ZipEntry"/> based on the <paramref name="fileName"/>.</returns>
+ public ZipEntry MakeFileEntry(string fileName, bool useFileSystem) {
+ return MakeFileEntry(fileName, null, useFileSystem);
}
/// <summary>
/// Make a new <see cref="ZipEntry"/> from a name.
/// </summary>
/// <param name="fileName">The name of the file to create a new entry for.</param>
+ /// <param name="entryName">An alternative name to be used for the new entry. Null if not applicable.</param>
/// <param name="useFileSystem">If true entry detail is retrieved from the file system if the file exists.</param>
/// <returns>Returns a new <see cref="ZipEntry"/> based on the <paramref name="fileName"/>.</returns>
- public ZipEntry MakeFileEntry(string fileName, bool useFileSystem)
+ public ZipEntry MakeFileEntry(string fileName, string entryName, bool useFileSystem)
{
- ZipEntry result = new ZipEntry(nameTransform_.TransformFile(fileName));
+ ZipEntry result = new ZipEntry(nameTransform_.TransformFile(entryName != null && entryName.Length > 0 ? entryName : fileName));
result.IsUnicodeText = isUnicodeText_;
int externalAttributes = 0;
View
3  src/Zip/ZipFile.cs
@@ -41,6 +41,7 @@
// 2009-12-22 Z-1649 Added AES support
// 2010-03-02 Z-1650 Fixed updating ODT archives in memory. Exposed exceptions in updating.
// 2010-05-25 Z-1663 Fixed exception when testing local header compressed size of -1
+// 2012-11-29 Z-1684 Fixed ZipFile.Add(string fileName, string entryName) losing the file TimeStamp
using System;
using System.Collections;
@@ -1647,7 +1648,7 @@ public void Add(string fileName, string entryName)
}
CheckUpdating();
- AddUpdate(new ZipUpdate(fileName, EntryFactory.MakeFileEntry(entryName)));
+ AddUpdate(new ZipUpdate(fileName, EntryFactory.MakeFileEntry(fileName, entryName, true)));
}

1 comment on commit 5f57a54

@davidpierson
Collaborator

Bugtracker reference

ZIP-1684 - File TimeStamp is lost via ZipFile.Add with modified entryname
http://bugtracker.sharpdevelop.net/issue/ViewIssue.aspx?id=1684&PROJID=2

Please sign in to comment.
Something went wrong with that request. Please try again.