feat: follow directory symlinks during license file search - #554
Open
Eljees wants to merge 1 commit into
Open
Conversation
Resolve and search symlinked directories instead of skipping them, so license files that are only reachable through a directory symlink (e.g. the snap package layout in anchore#70) are discovered. Each directory is resolved with filepath.EvalSymlinks and searched at most once, which terminates symlink cycles such as a -> b -> a. The walk runs against the resolved path because WalkDir applies lstat semantics to its root as well and would not descend into a symlinked directory. Files are deduplicated by resolved path so a license reachable both directly and through a symlink is only reported once. Broken symlinks are still skipped, and skipped directory names are honored for symlinks too. Fixes anchore#401 Signed-off-by: Eljees <3.14hell@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #401
Summary
grant's local license-file search now resolves and searches symlinked directories instead of skipping them, so licenses that are only reachable through a directory symlink (the snap layout from #70) are discovered.Details
filepath.EvalSymlinksand searched at most once, so symlink cycles (a -> b -> a, or a link back to the scan root) terminate.filepath.WalkDirapplies lstat semantics to its root as well, so walking a symlinked directory by its link path would not descend into it.skipDirectoriesnames are honored for directory symlinks too.skipSymlinkwas replaced bysymlinkTarget, which distinguishes "not a symlink" / "symlink to dir" / "broken symlink" instead of collapsing the last two into a single skip.Tests
TestSearchLicenseFiles_Symlinksupdated and extended (go test ./grant/passes):follows symlink to directory(wasskips symlink to directory)finds license only reachable through a symlinked directory— new; fails without this changeterminates on symlink cycles— new; a directory that symlinks back to its parentfollows symlink to fileandskips broken symlinkcases still pass