File tree Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ import (
13
13
14
14
"github.com/aquasecurity/fanal/analyzer"
15
15
"github.com/aquasecurity/fanal/extractor"
16
+ "github.com/aquasecurity/fanal/types"
17
+ "github.com/aquasecurity/fanal/utils"
16
18
)
17
19
18
20
func init () {
@@ -22,6 +24,9 @@ func init() {
22
24
type rpmCmdPkgAnalyzer struct {}
23
25
24
26
func (a rpmCmdPkgAnalyzer ) Analyze (fileMap extractor.FileMap ) (pkgs []analyzer.Package , err error ) {
27
+ if ! utils .IsCommandAvailable ("rpm" ) {
28
+ return nil , types .ErrNoRpmCmd
29
+ }
25
30
var parsedPkgs []analyzer.Package
26
31
detected := false
27
32
for _ , filename := range a .RequiredFiles () {
Original file line number Diff line number Diff line change @@ -2,4 +2,7 @@ package types
2
2
3
3
import "golang.org/x/xerrors"
4
4
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
+ )
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package utils
3
3
import (
4
4
"fmt"
5
5
"os"
6
+ "os/exec"
6
7
"path/filepath"
7
8
)
8
9
@@ -29,3 +30,10 @@ func StringInSlice(a string, list []string) bool {
29
30
}
30
31
return false
31
32
}
33
+
34
+ func IsCommandAvailable (name string ) bool {
35
+ if _ , err := exec .LookPath (name ); err != nil {
36
+ return false
37
+ }
38
+ return true
39
+ }
You can’t perform that action at this time.
0 commit comments