Skip to content

Commit

Permalink
fix zip directory error
Browse files Browse the repository at this point in the history
  • Loading branch information
yangxuilyx committed Jan 13, 2025
1 parent cf556ec commit 937e215
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/c#/GeneralUpdate.Common/Compress/ZipCompressionStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void Compress(string sourceDirectoryName
foreach (var toZipFileKey in toZipFileDictionaryList.Keys)
{
if (toZipFileKey == destinationArchiveFileName) continue;

var toZipedFileName = Path.GetFileName(toZipFileKey);
var toDelArchives = new List<ZipArchiveEntry>();
foreach (var zipArchiveEntry in archive.Entries)
Expand Down Expand Up @@ -84,8 +84,8 @@ public void Compress(string sourceDirectoryName
var toDelArchives = new List<ZipArchiveEntry>();
foreach (var zipArchiveEntry in archive.Entries)
{
if (toZipedFileName != null
&& (zipArchiveEntry.FullName.StartsWith(toZipedFileName)|| toZipedFileName.StartsWith(zipArchiveEntry.FullName)))
if (toZipedFileName != null
&& (zipArchiveEntry.FullName.StartsWith(toZipedFileName) || toZipedFileName.StartsWith(zipArchiveEntry.FullName)))
{
toDelArchives.Add(zipArchiveEntry);
}
Expand All @@ -101,13 +101,13 @@ public void Compress(string sourceDirectoryName
}
}
}
catch(Exception exception)
catch (Exception exception)
{
Debug.WriteLine(exception);
throw new Exception($"Failed to compress archive: {exception.Message}");
}
}

/// <summary>
/// Unzip the Zip file and save it to the specified target path folder .
/// </summary>
Expand All @@ -120,7 +120,7 @@ public void Decompress(string zipFilePath, string unZipDir, Encoding encoding)
{
var dirSeparatorChar = Path.DirectorySeparatorChar.ToString();
unZipDir = unZipDir.EndsWith(dirSeparatorChar) ? unZipDir : unZipDir + dirSeparatorChar;

var directoryInfo = new DirectoryInfo(unZipDir);
if (!directoryInfo.Exists)
{
Expand All @@ -138,14 +138,14 @@ public void Decompress(string zipFilePath, string unZipDir, Encoding encoding)
for (int i = 0; i < archive.Entries.Count; i++)
{
var entries = archive.Entries[i];
if (entries.FullName.EndsWith(dirSeparatorChar))
var pattern = $"^{dirSeparatorChar}*";
var entryFilePath = Regex.Replace(entries.FullName.Replace("/", dirSeparatorChar), pattern,
"");
if (entryFilePath.EndsWith(dirSeparatorChar))
{
continue;
}

var pattern = $"^{dirSeparatorChar}*";
var entryFilePath = Regex.Replace(entries.FullName.Replace("/", dirSeparatorChar), pattern,
"");
var filePath = directoryInfo + entryFilePath;
var greatFolder = Directory.GetParent(filePath);
if (greatFolder is not null && !greatFolder.Exists)
Expand Down

0 comments on commit 937e215

Please sign in to comment.