mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
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:
parent
cfbb9f703b
commit
a00a3df10c
@ -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) {
|
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 runtime.GOOS == WindowsOS {
|
||||||
|
p = posixToWindows(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
linkTarget, err = filepath.EvalSymlinks(p)
|
||||||
|
|
||||||
|
if runtime.GOOS == WindowsOS {
|
||||||
|
p = windowsToPosix(p)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("unable to readlink for path=%q: %w", p, err)
|
return "", fmt.Errorf("unable to readlink for path=%q: %w", p, err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if filepath.IsAbs(linkTarget) {
|
if filepath.IsAbs(linkTarget) {
|
||||||
// if the link is absolute (e.g, /bin/ls -> /bin/busybox) we need to
|
// if the link is absolute (e.g, /bin/ls -> /bin/busybox) we need to
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user