@@ -43,6 +43,9 @@ import (
43
43
"github.com/sirupsen/logrus"
44
44
)
45
45
46
+ //RPM macros file location
47
+ const rpmMacros string = "/usr/lib/rpm/macros"
48
+
46
49
//RPM command to extract packages from the rpm database
47
50
var rpmCmd = []string {
48
51
"rpm" , "--nodigest" , "--nosignature" ,
@@ -97,7 +100,7 @@ func (a RPMAnalyzer) getPackages(image pkgutil.Image) (map[string]util.PackageIn
97
100
98
101
packages , err := rpmDataFromImageFS (image )
99
102
if err != nil {
100
- logrus .Warn ( "Trying to run the RPM binary of the image in a container" )
103
+ logrus .Info ( "Running RPM binary from image in a container" )
101
104
return rpmDataFromContainer (image )
102
105
}
103
106
return packages , err
@@ -130,15 +133,18 @@ func rpmDataFromImageFS(image pkgutil.Image) (map[string]util.PackageInfo, error
130
133
// rpmDBPath tries to get the RPM database path from the /usr/lib/rpm/macros
131
134
// file in the image rootfs.
132
135
func rpmDBPath (rootFSPath string ) (string , error ) {
133
- rpmMacros , err := os .Open (filepath .Join (rootFSPath , "usr/lib/rpm/macros" ))
136
+ imgMacrosFile , err := os .Open (filepath .Join (rootFSPath , rpmMacros ))
134
137
if err != nil {
135
138
return "" , err
136
139
}
137
- defer rpmMacros .Close ()
140
+ defer imgMacrosFile .Close ()
138
141
139
- scanner := bufio .NewScanner (rpmMacros )
142
+ scanner := bufio .NewScanner (imgMacrosFile )
140
143
for scanner .Scan () {
141
144
line := strings .TrimSpace (scanner .Text ())
145
+
146
+ // We are looking for a macro definition like (form openSUSE Leap):
147
+ // %_dbpath %{_usr}/lib/sysimage/rpm
142
148
if strings .HasPrefix (line , "%_dbpath" ) {
143
149
fields := strings .Fields (line )
144
150
if len (fields ) < 2 {
0 commit comments