Skip to content

refactor recursiveScan function#739

Closed
Ritish134 wants to merge 1 commit into
chainguard-dev:mainfrom
Ritish134:main
Closed

refactor recursiveScan function#739
Ritish134 wants to merge 1 commit into
chainguard-dev:mainfrom
Ritish134:main

Conversation

@Ritish134
Copy link
Copy Markdown
Contributor

Breakdown of recursiveScan function: #497

  • Created initializeReport function to initialize and configure the malcontent.Report object.
  • I think Instead of relying on sync.Once to ensure that a match (or miss) is processed only once, I Created setMatchHandling function to do that, basically in this :
    Only the first goroutine to send a result to this channel succeeds due to the buffered capacity of 1.
    matchChan := make(chan matchResult, 1)

context.WithCancel is used to signal all concurrent goroutines to stop further processing once a match is found.

Let me know your thoughts on this @tstromberg

  • the logic for handling OCI image extraction (including the imageURI and ociExtractPath variables) moved into the helper function prepareScanPath.

  • The call to findFilesRecursively is now encapsulated within processPaths. This function is responsible for finding files and managing their subsequent processing.

  • Concurrency Handling logic moved to processWithConcurrency

  • File-specific processing logic into a separate function (processSingleFile)

  • storeFileReport to store individual file reports and
    storeArchiveReports For storing multiple file reports from a sync.Map

Signed-off-by: Ritish Srivastava <121374890+Ritish134@users.noreply.github.com>
@egibs
Copy link
Copy Markdown
Member

egibs commented Jan 13, 2025

Hey @Ritish134 -- appreciate the effort here! It seems like we were operating on the same wavelength with the proposed changes; however, I actually included a version of this in #734 as part of the larger migration to a newer Yara API and didn't see this until now.

As far as refactoring goes, there are some other areas that could use this attention, namely Generate in report.go and improving the performance/organization of File in programkind.go.

Let me know if you're interested in either of these. I'm happy to log Issues with further details!

@egibs egibs closed this Jan 13, 2025
@Ritish134
Copy link
Copy Markdown
Contributor Author

Thanks! @egibs for the update. Sure, I would definitely be interested in working on these areas, so I'll deep-dive in!
I'll keep you posted and let you know if I need any help along the way .

@Ritish134
Copy link
Copy Markdown
Contributor Author

Hi @egibs, I’ve opened PR #992 with changes to Generate in report.go, improvements to File in programkind.go, and a few additional minor updates.
Let me know if you’d like to see any adjustments!

Not sure why golangci-lint is failing.

@Ritish134
Copy link
Copy Markdown
Contributor Author

Also, if there’s any slightly more complex issue I could help with next, I’d love to take it on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants