Go: Fix buggy FindAllFilesWithName
implementation
#17900
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
It seems that our implementation of
FindAllFilesWithName
contained bugged logic wheredirsToSkip
was typically given a list of directory names (such asvendor
) and then compared these to the relative path of directories discovered byfilepath.WalkDir
(such as./vendor
). This resulted ingo.mod
andgo.work
files invendor
directories not getting skipped correctly, which was reported in #17893.Approach
@smowton implemented a handy
isGolangVendorDirectory
predicate as part of #17227, which already implements the correct check. To not duplicate this logic, I decided to moveisGolangVendorDirectory
from that package to the sharedutil
one. I then modifiedFindAllFilesWithName
to accept such predicate functions as arguments instead of an array of strings. I changed calls toFindAllFilesWithName
to use a (pre-defined) array containing theisGolangVendorDirectory
predicate instead of the"vendor"
string.I then added a problematic
vendor
directory to themixed-layout
integration test, containing ago.work
file.Alternatives
Instead of modifying
FindAllFilesWithName
to accept a list of predicates, we could just check that each path discovered byfilepath.WalkDir
ends in one of the excluded directory names.Open questions
vendor
directories in extraction #16925 and Go / configure-baseline: account for multiple vendor directories and theCODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS
setting #17227 we only modified the extractor logic for extractingvendor
directories that are contained within some other workspace. We didn't modify the autobuilder's project discovery logic to also permit finding workspaces invendor
directories. While making the changes for this fix, it wasn't clear to me what the autobuilder's workspace discovery project should do ifCODEQL_EXTRACTOR_GO_EXTRACT_VENDOR_DIRS
is set totrue
.