mirror of
https://github.com/trufflesecurity/trufflehog.git
synced 2024-11-10 07:04:24 +00:00
Export line number code (#962)
This commit is contained in:
parent
4e2ce4f6fe
commit
335ce85ce4
1 changed files with 12 additions and 7 deletions
|
@ -181,7 +181,7 @@ func (e *Engine) detectorWorker(ctx context.Context) {
|
|||
for originalChunk := range e.chunks {
|
||||
for chunk := range sources.Chunker(originalChunk) {
|
||||
atomic.AddUint64(&e.bytesScanned, uint64(len(chunk.Data)))
|
||||
fragStart, mdLine := fragmentFirstLine(chunk)
|
||||
fragStart, mdLine := FragmentFirstLine(chunk)
|
||||
for _, decoder := range e.decoders {
|
||||
var decoderType detectorspb.DecoderType
|
||||
switch decoder.(type) {
|
||||
|
@ -230,10 +230,7 @@ func (e *Engine) detectorWorker(ctx context.Context) {
|
|||
results = detectors.CleanResults(results)
|
||||
}
|
||||
for _, result := range results {
|
||||
if isGitSource(chunk.SourceType) {
|
||||
offset := FragmentLineOffset(chunk, &result)
|
||||
*mdLine = fragStart + offset
|
||||
}
|
||||
SetResultLineNumber(chunk, &result, fragStart, mdLine)
|
||||
result.DecoderType = decoderType
|
||||
e.results <- detectors.CopyMetadata(chunk, result)
|
||||
|
||||
|
@ -294,9 +291,9 @@ func FragmentLineOffset(chunk *sources.Chunk, result *detectors.Result) int64 {
|
|||
return 0
|
||||
}
|
||||
|
||||
// fragmentFirstLine returns the first line number of a fragment along with a pointer to the value to update in the
|
||||
// FragmentFirstLine returns the first line number of a fragment along with a pointer to the value to update in the
|
||||
// chunk metadata.
|
||||
func fragmentFirstLine(chunk *sources.Chunk) (int64, *int64) {
|
||||
func FragmentFirstLine(chunk *sources.Chunk) (int64, *int64) {
|
||||
var fragmentStart *int64
|
||||
switch metadata := chunk.SourceMetadata.GetData().(type) {
|
||||
case *source_metadatapb.MetaData_Git:
|
||||
|
@ -314,3 +311,11 @@ func fragmentFirstLine(chunk *sources.Chunk) (int64, *int64) {
|
|||
}
|
||||
return *fragmentStart, fragmentStart
|
||||
}
|
||||
|
||||
// SetResultLineNumber sets the line number in the provided result.
|
||||
func SetResultLineNumber(chunk *sources.Chunk, result *detectors.Result, fragStart int64, mdLine *int64) {
|
||||
if isGitSource(chunk.SourceType) {
|
||||
offset := FragmentLineOffset(chunk, result)
|
||||
*mdLine = fragStart + offset
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue