Skip to content

Commit

Permalink
Merge pull request #458 from Nexus-Mods/sevenzip-logging
Browse files Browse the repository at this point in the history
Log the 7z.exe output to have more info on extract failures
  • Loading branch information
Al12rs authored Jul 20, 2023
2 parents f4ac863 + 1282f4f commit dbd4332
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.InteropServices;
using System.Text;
using CliWrap;
using CliWrap.Exceptions;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -103,6 +104,7 @@ from sig in signatures
private async Task ExtractAllAsync_Impl(IStreamFactory sFn, AbsolutePath destination, CancellationToken token, IJob<IExtractor, Size> job)
{
TemporaryPath? spoolFile = null;
var processOutput = new StringBuilder();
try
{
AbsolutePath source;
Expand All @@ -124,6 +126,7 @@ private async Task ExtractAllAsync_Impl(IStreamFactory sFn, AbsolutePath destina

var totalSize = source.FileInfo.Size;
var lastPercent = 0;

job.Size = totalSize;

// NOTE: 7z.exe has a bug with long destination path with forwards `/` separators on windows,
Expand All @@ -137,6 +140,9 @@ private async Task ExtractAllAsync_Impl(IStreamFactory sFn, AbsolutePath destina
}, true)
.WithStandardOutputPipe(PipeTarget.ToDelegate(line =>
{
if (string.IsNullOrWhiteSpace(line)) return;
processOutput.Append($"[7z.exe] {line} \n");
if (line.Length <= 4 || line[3] != '%') return;
if (!int.TryParse(line.AsSpan()[..3], out var percentInt)) return;
Expand All @@ -156,6 +162,7 @@ private async Task ExtractAllAsync_Impl(IStreamFactory sFn, AbsolutePath destina
catch (CommandExecutionException ex)
{
_logger.LogError(ex, "While executing 7zip");
_logger.LogInformation("Output from the extractor, trying to extract file {File}:\n{Output}", sFn.Name, processOutput.ToString());
throw;
}
finally
Expand Down

0 comments on commit dbd4332

Please sign in to comment.