Skip to content

Commit

Permalink
add a fix for windows volumes
Browse files Browse the repository at this point in the history
Signed-off-by: Simar <[email protected]>
  • Loading branch information
simar7 committed Apr 6, 2023
1 parent c5869b5 commit adeeec3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/misconf/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ func getRootDir(filePath string) (string, error) {
}

// Scan detects misconfigurations.
// nolint: gocyclo
func (s *Scanner) Scan(ctx context.Context, files []types.File) ([]types.Misconfiguration, error) {
mapMemoryFS := make(map[string]*memoryfs.FS)
for t := range s.scanners {
Expand Down Expand Up @@ -315,7 +316,12 @@ func (s *Scanner) Scan(ctx context.Context, files []types.File) ([]types.Misconf
return nil, xerrors.Errorf("scanfs for %s scan from memoryfs failed: %w", t, err)
}
} else {
results, err = scanner.ScanFS(ctx, extrafs.OSDir(fmt.Sprintf("%c", os.PathSeparator)), rootDir)
// Support Windows paths
if volume := filepath.VolumeName(rootDir); volume != "" {
rootDir = strings.TrimPrefix(filepath.ToSlash(rootDir), volume+"/")
}

results, err = scanner.ScanFS(ctx, extrafs.OSDir("/"), rootDir)
if err != nil {
return nil, xerrors.Errorf("scanfs for %s scan failed: %w", t, err)
}
Expand Down

0 comments on commit adeeec3

Please sign in to comment.