Skip to content

Commit

Permalink
Merge #2287 Capture error details from SharpZipLib for invalid ZIPs
Browse files Browse the repository at this point in the history
  • Loading branch information
politas committed Feb 18, 2018
2 parents 37fea0f + 361527e commit 3a742fe
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions Core/Net/NetFileCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ public string GetCachedZip(Uri url)
}

/// <summary>
/// Check whether a ZIP file is validation
/// Check whether a ZIP file is valid
/// </summary>
/// <param name="filename">path to zip file to check</param>
/// <param name="filename">Path to zip file to check</param>
/// <param name="invalidReason">Description of problem with the file</param>
/// <returns>
/// True if valid, false otherwise. See invalidReason param for explanation.
Expand All @@ -224,15 +224,27 @@ public static bool ZipValid(string filename, out string invalidReason)
{
using (ZipFile zip = new ZipFile(filename))
{
// Perform CRC check.
if (zip.TestArchive(true))
string zipErr = null;
// Perform CRC and other checks
if (zip.TestArchive(true, TestStrategy.FindFirstError,
(TestStatus st, string msg) =>
{
// This delegate is called as TestArchive proceeds through its
// steps, both routine and abnormal.
// The second parameter is non-null if an error occurred.
if (st != null && !st.EntryValid && !string.IsNullOrEmpty(msg))
{
// Capture the error string so we can return it
zipErr = $"Error in step {st.Operation} for {st.Entry?.Name}: {msg}";
}
}))
{
invalidReason = "";
return true;
}
else
{
invalidReason = "ZipFile.TestArchive(true) returned false";
invalidReason = zipErr ?? "ZipFile.TestArchive(true) returned false";
return false;
}
}
Expand Down

0 comments on commit 3a742fe

Please sign in to comment.