-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add RPM packages support to the package dataset (cherry picked from commit 99d09ea)
- Loading branch information
Showing
9 changed files
with
518 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
// +build !windows | ||
|
||
package pkg | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"strconv" | ||
"strings" | ||
"time" | ||
) | ||
|
||
func rpmPackagesByExec() ([]*Package, error) { | ||
format := "%{NAME}|%{VERSION}|%{RELEASE}|%{ARCH}|%{LICENSE}|%{INSTALLTIME}|%{SIZE}|%{URL}|%{SUMMARY}\\n" | ||
out, err := exec.Command("/usr/bin/rpm", "--qf", format, "-qa").Output() | ||
if err != nil { | ||
return nil, fmt.Errorf("Error running rpm -qa command: %v", err) | ||
} | ||
|
||
lines := strings.Split(string(out), "\n") | ||
var packages []*Package | ||
for _, line := range lines { | ||
if len(strings.TrimSpace(line)) == 0 { | ||
continue | ||
} | ||
words := strings.SplitN(line, "|", 9) | ||
if len(words) < 9 { | ||
return nil, fmt.Errorf("line '%s' doesn't have enough elements", line) | ||
} | ||
pkg := Package{ | ||
Name: words[0], | ||
Version: words[1], | ||
Release: words[2], | ||
Arch: words[3], | ||
License: words[4], | ||
// install time - 5 | ||
// size - 6 | ||
URL: words[7], | ||
Summary: words[8], | ||
} | ||
ts, err := strconv.ParseInt(words[5], 10, 64) | ||
if err != nil { | ||
return nil, fmt.Errorf("error converting %s to string: %v", words[5], err) | ||
} | ||
pkg.InstallTime = time.Unix(ts, 0) | ||
|
||
pkg.Size, err = strconv.ParseUint(words[6], 10, 64) | ||
if err != nil { | ||
return nil, fmt.Errorf("error converting %s to string: %v", words[6], err) | ||
} | ||
|
||
// Avoid "(none)" in favor of empty strings | ||
if pkg.URL == "(none)" { | ||
pkg.URL = "" | ||
} | ||
if pkg.Arch == "(none)" { | ||
pkg.Arch = "" | ||
} | ||
|
||
packages = append(packages, &pkg) | ||
|
||
} | ||
|
||
return packages, nil | ||
} |
Oops, something went wrong.