fix: use filepath.EvalSymlinks if os.Readlink fails to evaluate the link (#1884)

Signed-off-by: DD (Devdatta) Deshpande <dd@codewits.in>
Co-authored-by: Keith Zantow <kzantow@gmail.com>
This commit is contained in:
DD (Devdatta) Deshpande 2023-07-06 00:19:22 +05:30 committed by GitHub
parent cfbb9f703b
commit a00a3df10c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -331,9 +331,21 @@ func (r directoryIndexer) addFileToIndex(p string, info os.FileInfo) error {
func (r directoryIndexer) addSymlinkToIndex(p string, info os.FileInfo) (string, error) {
linkTarget, err := os.Readlink(p)
if err != nil {
if runtime.GOOS == WindowsOS {
p = posixToWindows(p)
}
linkTarget, err = filepath.EvalSymlinks(p)
if runtime.GOOS == WindowsOS {
p = windowsToPosix(p)
}
if err != nil {
return "", fmt.Errorf("unable to readlink for path=%q: %w", p, err)
}
}
if filepath.IsAbs(linkTarget) {
// if the link is absolute (e.g, /bin/ls -> /bin/busybox) we need to