Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
Update SevenZipCompressor.cs (#1)
Browse files Browse the repository at this point in the history
Fix for issue: #153. 
Code changes to update Password in SevenZipCompressor for append operations. 
This fix is based on code changes done under: #20
  • Loading branch information
amarendrabiorad committed Jan 24, 2022
1 parent 1258e9b commit e373382
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions SevenZip/SevenZipCompressor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,8 @@ public void CompressFilesEncrypted(string archiveName, int commonRootLength, str
return;
}
}

UpdateCompressorPassword(password);

if (_volumeSize == 0 || !_compressingFilesOnDisk)
{
Expand Down Expand Up @@ -1499,7 +1501,9 @@ public void CompressStreamDictionary(IDictionary<string, Stream> streamDictionar
{
ValidateStream(archiveStream);
}


UpdateCompressorPassword(password);

if (streamDictionary.Where(
pair => pair.Value != null && (!pair.Value.CanSeek || !pair.Value.CanRead)).Any(
pair => !ThrowException(null,
Expand Down Expand Up @@ -1664,11 +1668,7 @@ public void ModifyArchive(string archiveName, IDictionary<int, string> newFileNa
}
}

if (!string.IsNullOrEmpty(password) && string.IsNullOrEmpty(Password))
{
// When modifying an encrypted archive, Password is not set in the SevenZipCompressor.
Password = password;
}
UpdateCompressorPassword(password);

try
{
Expand Down Expand Up @@ -1862,5 +1862,18 @@ private static string[] GetFullFilePaths(IEnumerable<string> fileFullNames)
{
return fileFullNames.Select(Path.GetFullPath).ToArray();
}

/// <summary>
/// Check and update password in SevenZipCompressor
/// </summary>
/// <param name="password"></param>
private void UpdateCompressorPassword(string password)
{
if (!string.IsNullOrEmpty(password) && string.IsNullOrEmpty(Password))
{
// When modifying an encrypted archive, Password is not set in the SevenZipCompressor.
Password = password;
}
}
}
}

0 comments on commit e373382

Please sign in to comment.