Skip to content

Commit

Permalink
fix: handle dirs that are not dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
elsapet committed Nov 2, 2022
1 parent 1d6247f commit a1c6bcf
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions pkg/detectors/dotnet/dotnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dotnet

import (
"io/ioutil"
"os"
"path/filepath"

"github.com/bearer/curio/pkg/detectors/types"
Expand Down Expand Up @@ -80,14 +81,19 @@ func (detector *detector) ProcessFile(file *file.FileInfo, dir *file.Path, repor
}

func isProject(path string) (bool, error) {
fileInfos, err := ioutil.ReadDir(path)
handleDir, err := isDir(path)
if err != nil {
return false, err
}

for _, file := range fileInfos {
if filepath.Ext(file.Name()) == fileProjectExt {
testMatch, errMatch := filepath.Match("*Test*", file.Name())
if handleDir {
fileInfos, err := ioutil.ReadDir(path)
if err != nil {
return false, err
}

for _, file := range fileInfos {
testMatch, errMatch := matchFilepath(file.Name())
if errMatch != nil {
return false, errMatch
}
Expand All @@ -98,5 +104,36 @@ func isProject(path string) (bool, error) {
}
}

// we have a file and not a directory
fileInfo, err := os.Stat(path)
if err != nil {
return false, err
}

testMatch, errMatch := matchFilepath(fileInfo.Name())
if errMatch != nil {
return false, errMatch
}
if !testMatch {
return true, nil
}

return false, nil
}

func matchFilepath(filename string) (bool, error) {
if filepath.Ext(filename) == fileProjectExt {
return filepath.Match("*Test*", filename)
}

return false, nil
}

func isDir(path string) (bool, error) {
fileInfo, err := os.Stat(path)
if err != nil {
return false, err
}

return fileInfo.IsDir(), nil
}

0 comments on commit a1c6bcf

Please sign in to comment.