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

Commit

Permalink
Merge pull request #154 from amarendrabiorad/master
Browse files Browse the repository at this point in the history
Fixed append operation for archives with encrypted headers.
  • Loading branch information
squid-box committed Mar 22, 2023
2 parents 88f48c3 + c834a78 commit d4cd869
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">The password to use.</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 d4cd869

Please sign in to comment.