+45
-14
lines changedFilter options
+45
-14
lines changed Original file line number Diff line number Diff line change
@@ -566,11 +566,11 @@ internal static string ExtractExcerpt(TextContainer text, Location start, Locati
566
566
567
567
int startLineNumber =
568
568
start.Line < 0 ? 0 : start.Line > text.LineEnds.Count ? text.LineEnds.Count - 1 : start.Line;
569
-
int endLineNUmber =
569
+
int endLineNumber =
570
570
end.Line < 0 ? 0 : end.Line > text.LineEnds.Count ? text.LineEnds.Count - 1 : end.Line;
571
571
// First we try to include the number of lines of context requested
572
572
var excerptStartLine = Math.Max(0, startLineNumber - context);
573
-
var excerptEndLine = Math.Min(text.LineEnds.Count - 1, endLineNUmber + context);
573
+
var excerptEndLine = Math.Min(text.LineEnds.Count - 1, endLineNumber + context);
574
574
var startIndex = text.LineStarts[excerptStartLine];
575
575
var endIndex = text.LineEnds[excerptEndLine] + 1;
576
576
// Maximum number of characters to capture on each side
Original file line number Diff line number Diff line change
@@ -449,12 +449,14 @@ public string GetLineContent(int line)
449
449
450
450
/// <summary>
451
451
/// Returns location (Line, Column) for given index in text
452
+
/// If the index is beyond the end of the file, clamps to the end
452
453
/// </summary>
453
454
/// <param name="index"> Position in text (line is one-indexed)</param>
454
455
/// <returns> Location </returns>
455
456
public Location GetLocation(int index)
456
457
{
457
458
for (var i = 1; i < LineEnds.Count; i++)
459
+
{
458
460
if (LineEnds[i] >= index)
459
461
{
460
462
return new Location
@@ -463,6 +465,17 @@ public Location GetLocation(int index)
463
465
Line = i
464
466
};
465
467
}
468
+
}
469
+
470
+
// If the index is beyond the end of the file, clamp to the end of the file
471
+
if (index > LineEnds[^1])
472
+
{
473
+
return new Location()
474
+
{
475
+
Column = LineEnds[^1] - LineStarts[^1],
476
+
Line = LineEnds.Count
477
+
};
478
+
}
466
479
467
480
return new Location();
468
481
}
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
4
4
using System;
5
5
using System.Collections.Concurrent;
6
6
using System.Collections.Generic;
7
+
using System.Collections.Immutable;
7
8
using System.Diagnostics;
8
9
using System.Globalization;
9
10
using System.IO;
@@ -771,21 +772,38 @@ private IEnumerable<FileEntry> EnumerateFileEntries()
771
772
772
773
if (contents != null)
773
774
{
774
-
if (_options.DisableCrawlArchives)
775
+
IList<FileEntry> entriesToYield = new List<FileEntry>();
776
+
try
775
777
{
776
-
yield return new FileEntry(srcFile, contents);
778
+
if (_options.DisableCrawlArchives)
779
+
{
780
+
entriesToYield.Add(new FileEntry(srcFile, contents));
781
+
}
782
+
else
783
+
{
784
+
// Use MemoryStreamCutoff = 1 to force using FileStream with DeleteOnClose for backing, and avoid memory exhaustion.
785
+
ExtractorOptions opts = new()
786
+
{
787
+
Parallel = false, DenyFilters = _options.FilePathExclusions, MemoryStreamCutoff = 1
788
+
};
789
+
// This works if the contents contain any kind of file.
790
+
// If the file is an archive this gets all the entries it contains.
791
+
// If the file is not an archive, the stream is wrapped in a FileEntry container and yielded
792
+
entriesToYield = extractor.Extract(srcFile, contents, opts).ToImmutableList();
793
+
}
777
794
}
778
-
else
795
+
catch (Exception e)
779
796
{
780
-
// Use MemoryStreamCutoff = 1 to force using FileStream with DeleteOnClose for backing, and avoid memory exhaustion.
781
-
ExtractorOptions opts = new()
782
-
{
783
-
Parallel = false, DenyFilters = _options.FilePathExclusions, MemoryStreamCutoff = 1
784
-
};
785
-
// This works if the contents contain any kind of file.
786
-
// If the file is an archive this gets all the entries it contains.
787
-
// If the file is not an archive, the stream is wrapped in a FileEntry container and yielded
788
-
foreach (var entry in extractor.Extract(srcFile, contents, opts)) yield return entry;
797
+
_logger.LogDebug(
798
+
"Failed to analyze file {Path}. {Type}:{Message}. ({StackTrace})",
799
+
srcFile, e.GetType(), e.Message, e.StackTrace);
800
+
_metaDataHelper?.Metadata.Files.Add(new FileRecord
801
+
{ FileName = srcFile, Status = ScanState.Error });
802
+
}
803
+
804
+
foreach (var entry in entriesToYield)
805
+
{
806
+
yield return entry;
789
807
}
790
808
}
791
809
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4