mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
#22473 - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files) for more information. - [X] Added/updated tests - [X] Manual QA for all new/changed functionality - For Orbit and Fleet Desktop changes: - [x] Manual QA must be performed in the three main OSs, macOS, Windows and Linux. --------- Co-authored-by: RachelElysia <71795832+RachelElysia@users.noreply.github.com> Co-authored-by: Ian Littman <iansltx@gmail.com>
33 lines
696 B
Go
33 lines
696 B
Go
package file
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"fmt"
|
|
"io"
|
|
|
|
"github.com/cavaliergopher/rpm"
|
|
)
|
|
|
|
func ExtractRPMMetadata(r io.Reader) (*InstallerMetadata, error) {
|
|
h := sha256.New()
|
|
r = io.TeeReader(r, h)
|
|
|
|
// Read the package headers
|
|
pkg, err := rpm.Read(r)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("read headers: %w", err)
|
|
}
|
|
// r is now positioned at the RPM payload.
|
|
|
|
// Ensure the whole file is read to get the correct hash
|
|
if _, err := io.Copy(io.Discard, r); err != nil {
|
|
return nil, fmt.Errorf("read all RPM content: %w", err)
|
|
}
|
|
|
|
return &InstallerMetadata{
|
|
Name: pkg.Name(),
|
|
Version: pkg.Version(),
|
|
SHASum: h.Sum(nil),
|
|
PackageIDs: []string{pkg.Name()},
|
|
}, nil
|
|
}
|