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-05 14:49:22 -04:00
committed by GitHub
co-authored by Keith Zantow
parent cfbb9f703b
commit a00a3df10c
@@ -332,7 +332,19 @@ 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 {
return "", fmt.Errorf("unable to readlink for path=%q: %w", p, err)
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) {