Skip to content

Commit 3841cf6

Browse files
authored
Check whether rpm is installed (fanal#39)
* Check whether rpm is installed * Apply the review
1 parent cdeb41a commit 3841cf6

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

analyzer/pkg/rpmcmd/rpm.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313

1414
"github.com/aquasecurity/fanal/analyzer"
1515
"github.com/aquasecurity/fanal/extractor"
16+
"github.com/aquasecurity/fanal/types"
17+
"github.com/aquasecurity/fanal/utils"
1618
)
1719

1820
func init() {
@@ -22,6 +24,9 @@ func init() {
2224
type rpmCmdPkgAnalyzer struct{}
2325

2426
func (a rpmCmdPkgAnalyzer) Analyze(fileMap extractor.FileMap) (pkgs []analyzer.Package, err error) {
27+
if !utils.IsCommandAvailable("rpm") {
28+
return nil, types.ErrNoRpmCmd
29+
}
2530
var parsedPkgs []analyzer.Package
2631
detected := false
2732
for _, filename := range a.RequiredFiles() {

types/error.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ package types
22

33
import "golang.org/x/xerrors"
44

5-
var InvalidURLPattern = xerrors.New("Invalid url pattern")
5+
var (
6+
InvalidURLPattern = xerrors.New("invalid url pattern")
7+
ErrNoRpmCmd = xerrors.New("no rpm command")
8+
)

utils/utils.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package utils
33
import (
44
"fmt"
55
"os"
6+
"os/exec"
67
"path/filepath"
78
)
89

@@ -29,3 +30,10 @@ func StringInSlice(a string, list []string) bool {
2930
}
3031
return false
3132
}
33+
34+
func IsCommandAvailable(name string) bool {
35+
if _, err := exec.LookPath(name); err != nil {
36+
return false
37+
}
38+
return true
39+
}

0 commit comments

Comments
 (0)