From a00a3df10c3a20566c10d6d42de6d1a4bfbcea5d Mon Sep 17 00:00:00 2001
From: "DD (Devdatta) Deshpande"
Date: Thu, 6 Jul 2023 00:19:22 +0530
Subject: [PATCH] fix: use filepath.EvalSymlinks if os.Readlink fails to
evaluate the link (#1884)
Signed-off-by: DD (Devdatta) Deshpande
Co-authored-by: Keith Zantow
---
syft/internal/fileresolver/directory_indexer.go | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/syft/internal/fileresolver/directory_indexer.go b/syft/internal/fileresolver/directory_indexer.go
index 47349a445..01f332a3d 100644
--- a/syft/internal/fileresolver/directory_indexer.go
+++ b/syft/internal/fileresolver/directory_indexer.go
@@ -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) {