Skip to content

Commit 47c6cec

Browse files
authored
fix(scanner/redhatbase): update procPathToFQPN (#2363)
1 parent 340fbb2 commit 47c6cec

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

scanner/redhatbase.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -973,14 +973,19 @@ func (o *redhatBase) parseNeedsRestarting(stdout string) (procs []models.NeedRes
973973
// procPathToFQPN returns Fully-Qualified-Package-Name from the command
974974
func (o *redhatBase) procPathToFQPN(execCommand string) (string, error) {
975975
execCommand = strings.ReplaceAll(execCommand, "\x00", " ") // for CentOS6.9
976-
path := strings.Fields(execCommand)[0]
977-
cmd := `LANGUAGE=en_US.UTF-8 rpm -qf --queryformat "%{NAME}-%{EPOCH}:%{VERSION}-%{RELEASE}\n" ` + path
978-
r := o.exec(cmd, noSudo)
976+
cmd := fmt.Sprintf("%s %s", o.rpmQf(), strings.Fields(execCommand)[0])
977+
r := o.exec(util.PrependProxyEnv(cmd), noSudo)
979978
if !r.isSuccess() {
980979
return "", xerrors.Errorf("Failed to SSH: %s", r)
981980
}
982-
fqpn := strings.TrimSpace(r.Stdout)
983-
return strings.ReplaceAll(fqpn, "-(none):", "-"), nil
981+
pack, ignroed, err := o.parseRpmQfLine(r.Stdout)
982+
if err != nil {
983+
return "", xerrors.Errorf("Failed to parse rpm -qf line: %s, err: %+v", r.Stdout, err)
984+
}
985+
if ignroed {
986+
return "", xerrors.Errorf("Failed to return FQPN. line: %s, err: ignore line", r.Stdout)
987+
}
988+
return pack.FQPN(), nil
984989
}
985990

986991
func (o *redhatBase) getOwnerPkgs(paths []string) (names []string, _ error) {

0 commit comments

Comments
 (0)