Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Not able to scan volume mounted to folder #1828

Closed
dd-cws opened this issue May 19, 2023 · 4 comments · Fixed by #1884
Closed

[Windows] Not able to scan volume mounted to folder #1828

dd-cws opened this issue May 19, 2023 · 4 comments · Fixed by #1884
Labels
bug Something isn't working

Comments

@dd-cws
Copy link
Contributor

dd-cws commented May 19, 2023

What happened:
syft fails to read directory which has a volume mounted on it.
Say F: is mounted on C:\Temp\Mounts\F and syft is executed as:
syft.exe packages dir:C:\Temp\Mounts\
it fails with following error:

[0000]  WARN unable to access path="/C/Temp/Mounts/F": unable to readlink for path="/C/Temp/Mounts/F": readlink /C/Temp/Mounts/F: The system cannot find the path specified.
No packages discovered

What you expected to happen:
syft should scan the entire folder C:\Temp\Mounts including mounted volume

Steps to reproduce the issue:
Create a folder C:\Temp\Mounts\F
Follow below steps to mount F: drive to C:\Temp\Mounts\F

  1. Create empty folder C:\Temp\Mounts\F
  2. Press Win + R keys to open Run and type diskmgmt.msc into Run and hit enter
  3. In the disk management UI find F: drive, right click and select Change Drive Letter and Paths
  4. Click on Add
  5. In the textbox type C:\Temp\Mounts\F and click ok

Run syft.exe packages C:\Temp\Mounts

Anything else we need to know?:
The problem seems to be with the call to os.Readlink(p) in syft/source/directory_indexer.go in function addSymlinkToIndex
This should be replaced by filepath.EvalSymlinks(p)

Below is a quick patch that works for me:

diff --git a/syft/source/directory_indexer.go b/syft/source/directory_indexer.go
index e840a9dd..0cb2fe45 100644
--- a/syft/source/directory_indexer.go
+++ b/syft/source/directory_indexer.go
@@ -234,7 +234,16 @@ 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 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)
 	}

Environment:

  • Output of syft version: 0.80.0
  • OS (e.g: cat /etc/os-release or similar): Windows 11
@dd-cws dd-cws added the bug Something isn't working label May 19, 2023
@tgerla tgerla added this to OSS Jun 1, 2023
@tgerla
Copy link
Contributor

tgerla commented Jun 15, 2023

Hi @dd-cws, thank you for the issue and sorry for the delay replying. Would you be able to submit your patch as a pull request to the Syft repository? We can do some basic testing and hopefully merge it. Let us know if you need any help with that. We appreciate it.

@tgerla tgerla moved this to Awaiting Response in OSS Jun 15, 2023
@dd-cws
Copy link
Contributor Author

dd-cws commented Jun 18, 2023

Sure, I would be happy to do so. Let me go through your PR submission process and create one.

@kzantow
Copy link
Contributor

kzantow commented Jun 22, 2023

Hi @dd-cws, I'm a bit stuck following the instructions on step 3 (In the disk management UI find F: drive, right click and select Change Drive Letter and Paths) -- I do not see an F: drive, is there some other step that was missed to get this to show up?

@dd-cws
Copy link
Contributor Author

dd-cws commented Jun 22, 2023

Hey @kzantow, may be I wasn't clear in the instructions above. But F: drive is just an example I took. You can try to mount any drive available on your machine to a folder (even C:).
Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants