@@ -43,6 +43,9 @@ import (
4343 "github.com/sirupsen/logrus"
4444)
4545
46+ //RPM macros file location
47+ const rpmMacros string = "/usr/lib/rpm/macros"
48+
4649//RPM command to extract packages from the rpm database
4750var rpmCmd = []string {
4851 "rpm" , "--nodigest" , "--nosignature" ,
@@ -97,7 +100,7 @@ func (a RPMAnalyzer) getPackages(image pkgutil.Image) (map[string]util.PackageIn
97100
98101 packages , err := rpmDataFromImageFS (image )
99102 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" )
101104 return rpmDataFromContainer (image )
102105 }
103106 return packages , err
@@ -130,15 +133,18 @@ func rpmDataFromImageFS(image pkgutil.Image) (map[string]util.PackageInfo, error
130133// rpmDBPath tries to get the RPM database path from the /usr/lib/rpm/macros
131134// file in the image rootfs.
132135func 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 ))
134137 if err != nil {
135138 return "" , err
136139 }
137- defer rpmMacros .Close ()
140+ defer imgMacrosFile .Close ()
138141
139- scanner := bufio .NewScanner (rpmMacros )
142+ scanner := bufio .NewScanner (imgMacrosFile )
140143 for scanner .Scan () {
141144 line := strings .TrimSpace (scanner .Text ())
145+
146+ // We are looking for a macro definition like (form openSUSE Leap):
147+ // %_dbpath %{_usr}/lib/sysimage/rpm
142148 if strings .HasPrefix (line , "%_dbpath" ) {
143149 fields := strings .Fields (line )
144150 if len (fields ) < 2 {
0 commit comments