-
Notifications
You must be signed in to change notification settings - Fork 44
/
metadata.go
39 lines (34 loc) · 934 Bytes
/
metadata.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package rpmmd
import (
"fmt"
)
type RPM struct {
Type string `json:"type"` // must be 'rpm'
Name string `json:"name"`
Version string `json:"version"`
Release string `json:"release"`
Epoch *string `json:"epoch,omitempty"`
Arch string `json:"arch"`
Sigmd5 string `json:"sigmd5"`
Signature *string `json:"signature"`
}
// NEVRA string for the package
func (r RPM) String() string {
epoch := ""
if r.Epoch != nil {
epoch = *r.Epoch + ":"
}
return fmt.Sprintf("%s-%s%s-%s.%s", r.Name, epoch, r.Version, r.Release, r.Arch)
}
// Deduplicate a list of RPMs based on NEVRA string
func DeduplicateRPMs(rpms []RPM) []RPM {
rpmMap := make(map[string]struct{}, len(rpms))
uniqueRPMs := make([]RPM, 0, len(rpms))
for _, rpm := range rpms {
if _, added := rpmMap[rpm.String()]; !added {
rpmMap[rpm.String()] = struct{}{}
uniqueRPMs = append(uniqueRPMs, rpm)
}
}
return uniqueRPMs
}