Skip to content

Commit

Permalink
Z-1684 Fixed File Timestamp being lost via ZipFile.Add with modified …
Browse files Browse the repository at this point in the history
…entryname
  • Loading branch information
davidpierson committed Nov 30, 2012
1 parent 9322513 commit 5f57a54
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/Zip/IEntryFactory.cs
Expand Up @@ -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
Expand All @@ -59,6 +62,15 @@ public interface IEntryFactory
/// <returns>Returns a <see cref="ZipEntry">file entry</see> based on the <paramref name="fileName"/> passed.</returns>
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>
Expand Down
20 changes: 17 additions & 3 deletions src/Zip/ZipEntryFactory.cs
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/Zip/ZipFile.cs
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
}


Expand Down

1 comment on commit 5f57a54

@davidpierson
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.