Skip to content

Commit

Permalink
Better output when the overall timeout is hit. (#437)
Browse files Browse the repository at this point in the history
* Better output when the overall timeout is hit.

* Fix no matches case.
  • Loading branch information
gfs authored Mar 14, 2022
1 parent 93b2627 commit a697529
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
23 changes: 14 additions & 9 deletions AppInspector/Commands/AnalyzeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ public AnalyzeResult GetResult()

if (!_options.NoShowProgress)
{
var done = false;
var doneEnumerating = false;
ConcurrentBag<FileEntry> fileQueue = new();

_ = Task.Factory.StartNew(() =>
Expand All @@ -761,7 +761,7 @@ public AnalyzeResult GetResult()
{
WriteOnce.Error($"Overflowed while extracting file entries. Check the input for quines or zip bombs. {e.Message}");
}
done = true;
doneEnumerating = true;
});

var options = new ProgressBarOptions
Expand All @@ -775,7 +775,7 @@ public AnalyzeResult GetResult()

using (var pbar = new IndeterminateProgressBar("Enumerating Files.", options))
{
while (!done)
while (!doneEnumerating)
{
Thread.Sleep(_sleepDelay);
pbar.Message = $"Enumerating Files. {fileQueue.Count} Discovered.";
Expand All @@ -785,7 +785,7 @@ public AnalyzeResult GetResult()
pbar.Finished();
}
Console.WriteLine();
done = false;
var doneProcessing = false;

var options2 = new ProgressBarOptions
{
Expand All @@ -803,10 +803,10 @@ public AnalyzeResult GetResult()
_ = Task.Factory.StartNew(() =>
{
DoProcessing(fileQueue);
done = true;
doneProcessing = true;
});

while (!done)
while (!doneProcessing)
{
Thread.Sleep(_sleepDelay);
var current = _metaDataHelper.Files.Count;
Expand Down Expand Up @@ -837,16 +837,22 @@ public AnalyzeResult GetResult()
WriteOnce.Error(MsgHelp.GetString(MsgHelp.ID.ANALYZE_NOPATTERNS));
analyzeResult.ResultCode = AnalyzeResult.ExitCode.NoMatches;
}
else if (_metaDataHelper != null && _metaDataHelper.Metadata != null)
else
{
analyzeResult.ResultCode = AnalyzeResult.ExitCode.Success;
}

if (_metaDataHelper != null && _metaDataHelper.Metadata != null)
{
_metaDataHelper.Metadata.DateScanned = DateScanned.ToString();
_metaDataHelper.PrepareReport();
analyzeResult.Metadata = _metaDataHelper.Metadata; //replace instance with metadatahelper processed one
analyzeResult.ResultCode = AnalyzeResult.ExitCode.Success;
}

if (timedOut)
{
WriteOnce.Error("Overall processing timed out.");
analyzeResult.Metadata.TimedOut = true;
analyzeResult.ResultCode = AnalyzeResult.ExitCode.TimedOut;
}

Expand All @@ -861,7 +867,6 @@ void DoProcessing(IEnumerable<FileEntry> fileEntries)
if (!t.Wait(new TimeSpan(0, 0, 0, 0, _options.ProcessingTimeOut)))
{
timedOut = true;
WriteOnce.Error($"Processing timed out.");
cts.Cancel();
if (_metaDataHelper is not null)
{
Expand Down
18 changes: 15 additions & 3 deletions AppInspector/MetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,22 @@ public string LastUpdated
[JsonProperty(PropertyName = "dateScanned")]
public string? DateScanned { get; set; }

//stats

/// <summary>
/// True if the overall analysis timed out
/// </summary>
[JsonProperty(PropertyName = "timedOut")]
public bool TimedOut { get; set; }

//stats
/// <summary>
/// Total number of files in source path
/// </summary>
[JsonProperty(PropertyName = "totalFiles")]
public int TotalFiles { get { return Files.Count; } }

/// <summary>
/// Total number of files Timed out
/// Total number of files Timed out on an individual timeout
/// </summary>
[JsonProperty(PropertyName = "filesTimedOut")]
public int FilesTimedOut { get { return Files.Count(x => x.Status == ScanState.TimedOut); } }
Expand All @@ -97,14 +103,20 @@ public string LastUpdated
[JsonProperty(PropertyName = "filesSkipped")]
public int FilesSkipped { get { return Files.Count(x => x.Status == ScanState.Skipped); } }

/// <summary>
/// Total number of skipped files based on overall timeout
/// </summary>
[JsonProperty(PropertyName = "filesTimeOutSkipped")]
public int FilesTimeOutSkipped { get { return Files.Count(x => x.Status == ScanState.TimeOutSkipped); } }

/// <summary>
/// Total files with at least one result
/// </summary>
[JsonProperty(PropertyName = "filesAffected")]
public int FilesAffected { get { return Files.Count(x => x.Status == ScanState.Affected); } }

/// <summary>
/// Total files with at least one result
/// Number of files which encountered an error when processing other than timing out.
/// </summary>
[JsonProperty(PropertyName = "filesErrored")]
public int FileErrored { get { return Files.Count(x => x.Status == ScanState.Error); } }
Expand Down

0 comments on commit a697529

Please sign in to comment.