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

fix(detectors): handle dirs that are not dirs for dotnet #88

Merged
merged 1 commit into from
Nov 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}