Skip to content

feat: follow directory symlinks during license file search - #554

Open
Eljees wants to merge 1 commit into
anchore:mainfrom
Eljees:agent/follow-dir-symlinks
Open

feat: follow directory symlinks during license file search#554
Eljees wants to merge 1 commit into
anchore:mainfrom
Eljees:agent/follow-dir-symlinks

Conversation

@Eljees

@Eljees Eljees commented Jul 27, 2026

Copy link
Copy Markdown

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

  • Directories to search are kept in a small queue; a symlink whose target is a directory is queued instead of being handed to the classifier.
  • Each directory is resolved with filepath.EvalSymlinks and searched at most once, so symlink cycles (a -> b -> a, or a link back to the scan root) terminate.
  • The walk runs against the resolved path: filepath.WalkDir applies lstat semantics to its root as well, so walking a symlinked directory by its link path would not descend into it.
  • Matched files are deduplicated by resolved path, so a license reachable both directly and through a symlink is reported once.
  • Broken symlinks are still skipped, and skipDirectories names are honored for directory symlinks too.

skipSymlink was replaced by symlinkTarget, which distinguishes "not a symlink" / "symlink to dir" / "broken symlink" instead of collapsing the last two into a single skip.

Tests

TestSearchLicenseFiles_Symlinks updated and extended (go test ./grant/ passes):

  • follows symlink to directory (was skips symlink to directory)
  • finds license only reachable through a symlinked directory — new; fails without this change
  • terminates on symlink cycles — new; a directory that symlinks back to its parent
  • existing follows symlink to file and skips broken symlink cases still pass

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>
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.

Follow/resolve directory symlinks during license file search

1 participant