-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Enable optional symlink following for fs source #4565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| cleanPath := filepath.Clean(path) | ||
| fileInfo, err := os.Lstat(cleanPath) | ||
| var fileInfo fs.FileInfo | ||
| var err error | ||
| if s.followSymlinks { | ||
| fileInfo, err = os.Stat(cleanPath) | ||
| } else { | ||
| fileInfo, err = os.Lstat(cleanPath) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: I think this can be simplified via filepath.EvalSymlinks:
cleanPath := filepath.Clean(path)
if s.followSymlinks {
var err error
cleanPath, err = filepath.EvalSymlinks(path)
if err != nil { /* ... */ }
}| } | ||
|
|
||
| if fileInfo.Mode()&os.ModeSymlink != 0 { | ||
| if !s.followSymlinks && fileInfo.Mode()&os.ModeSymlink != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fileInfo.Mode() would always be non-symlink if os.Stat is used, right? Since Stat follows symlinks.
Octocat-dev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description:
Adds an option to follow symlinks in the fs source.
Checklist:
make test-community)?make lintthis requires golangci-lint)?