Skip to content

Follow symlinked dirs in recursive file mode#1639

Open
AkashKumar7902 wants to merge 1 commit into
ko-build:mainfrom
AkashKumar7902:issue-460-recursive-symlink-dirs
Open

Follow symlinked dirs in recursive file mode#1639
AkashKumar7902 wants to merge 1 commit into
ko-build:mainfrom
AkashKumar7902:issue-460-recursive-symlink-dirs

Conversation

@AkashKumar7902
Copy link
Copy Markdown

Summary

  • Teach recursive filename enumeration to descend into symlinked directories.
  • Keep non-recursive traversal from entering nested symlinked directories.
  • Add unit coverage for symlinked directory roots and nested symlinked directories.

Fixes #460

Validation

  • go test ./pkg/commands/options -run 'TestEnumerateFiles.*Symlinked' -count=1
  • go test ./pkg/commands/options -count=1
  • go test ./pkg/commands/... -count=1
  • go vet ./pkg/commands/...
  • git diff --check

Copilot AI review requested due to automatic review settings April 25, 2026 13:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates FilenameOptions file enumeration to follow symlinked directories during recursive traversal (to support ko apply --recursive -f ... use cases), while ensuring non-recursive traversal does not descend into nested symlinked directories.

Changes:

  • Replaced filepath.Walk-based enumeration with a custom recursive enumerator that can treat symlinked directories as directories.
  • Added cycle prevention for directory traversal via a visited set of resolved absolute paths.
  • Added unit tests covering recursive symlinked directory traversal and non-recursive behavior with nested symlinked directories.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pkg/commands/options/filestuff.go Implements custom traversal to follow symlinked directories (recursive) while skipping nested directories (non-recursive) and avoiding cycles.
pkg/commands/options/filestuff_test.go Adds unit coverage for symlinked directory roots / nested symlinked directories behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +68 to +76
if err != nil {
// Preserve the old behavior for file-like symlinks: if the entry was
// passed explicitly, stream it and let later file handling report errors.
if filename == root {
files <- filename
}
return nil
}
isDir = targetInfo.IsDir()
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When encountering a symlink, an os.Stat failure causes the entry to be silently ignored unless it was explicitly passed as root. This changes previous behavior for symlinked files discovered during directory traversal (e.g., a broken *.yaml symlink would previously be enumerated and then fail later during os.ReadFile), and can result in missing manifests with no error. Consider treating os.Stat errors as “not a directory” (continue through the normal extension filter / emission path) or returning the error so the user gets a clear failure instead of silently skipping the entry.

Suggested change
if err != nil {
// Preserve the old behavior for file-like symlinks: if the entry was
// passed explicitly, stream it and let later file handling report errors.
if filename == root {
files <- filename
}
return nil
}
isDir = targetInfo.IsDir()
if err == nil {
isDir = targetInfo.IsDir()
}

Copilot uses AI. Check for mistakes.
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
@AkashKumar7902 AkashKumar7902 force-pushed the issue-460-recursive-symlink-dirs branch from 5c5fefd to 37946b9 Compare April 29, 2026 22:01
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.

ko apply --recursive -f to follow symlinked directories

2 participants