Skip to content

Commit

Permalink
Merge pull request #3965 from daguiler/bugfix/DNN-42754
Browse files Browse the repository at this point in the history
Added retry to CompressionUtil.OpenCreate to prevent failures during site export
  • Loading branch information
mitchelsellers authored Aug 18, 2020
2 parents b098a16 + 7e165b6 commit 1642e97
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Dnn.ExportImport.Components.Common
using System.IO.MemoryMappedFiles;
using System.Linq;
using System.Text;
using DotNetNuke.Common.Utilities.Internal;

public static class CompressionUtil
{
Expand Down Expand Up @@ -199,6 +200,27 @@ public static bool AddFileToArchive(ZipArchive archive, string file, int folderO
/// <param name="archiveFileName"></param>
/// <returns></returns>
public static ZipArchive OpenCreate(string archiveFileName)
{
if (string.IsNullOrWhiteSpace(archiveFileName))
{
throw new ArgumentNullException(nameof(archiveFileName));
}

ZipArchive zip = null;

RetryableAction.RetryEverySecondFor30Seconds(
() => zip = OpenCreateUnsafe(archiveFileName),
$"{nameof(OpenCreateUnsafe)}(\"{archiveFileName}\")");

return zip;
}

/// <summary>
/// Open the archive file for read and write (no retry).
/// </summary>
/// <param name="archiveFileName">The full zip file path.</param>
/// <returns>A <see cref="ZipArchive"/> instance.</returns>
internal static ZipArchive OpenCreateUnsafe(string archiveFileName)
{
return File.Exists(archiveFileName)
? ZipFile.Open(archiveFileName, ZipArchiveMode.Update, Encoding.UTF8)
Expand Down

0 comments on commit 1642e97

Please sign in to comment.