Skip to content

Commit

Permalink
fix: use filepath.EvalSymlinks if os.Readlink fails to evaluate the l…
Browse files Browse the repository at this point in the history
…ink (anchore#1884)

Signed-off-by: DD (Devdatta) Deshpande <dd@codewits.in>
Co-authored-by: Keith Zantow <kzantow@gmail.com>
  • Loading branch information
dd-cws and kzantow authored Jul 5, 2023
1 parent b2bf9f1 commit 0db2960
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion syft/internal/fileresolver/directory_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 0db2960

Please sign in to comment.