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

@ -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) { func (r directoryIndexer) addSymlinkToIndex(p string, info os.FileInfo) (string, error) {
linkTarget, err := os.Readlink(p) linkTarget, err := os.Readlink(p)
if err != nil { 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) { if filepath.IsAbs(linkTarget) {