2020-07-10 02:36:45 +02:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
2021-04-03 21:33:56 +02:00
|
|
|
"strings"
|
2020-07-10 02:36:45 +02:00
|
|
|
|
|
|
|
"github.com/leonelquinteros/gotext"
|
|
|
|
|
2023-04-06 19:06:46 +02:00
|
|
|
"github.com/Jguer/aur"
|
|
|
|
"github.com/Jguer/go-alpm/v2"
|
|
|
|
|
2023-03-07 22:04:06 +01:00
|
|
|
"github.com/Jguer/yay/v12/pkg/stringset"
|
|
|
|
"github.com/Jguer/yay/v12/pkg/text"
|
2020-07-10 02:36:45 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type AURWarnings struct {
|
|
|
|
Orphans []string
|
|
|
|
OutOfDate []string
|
|
|
|
Missing []string
|
|
|
|
Ignore stringset.StringSet
|
2023-04-06 19:06:46 +02:00
|
|
|
|
|
|
|
log *text.Logger
|
2020-07-10 02:36:45 +02:00
|
|
|
}
|
|
|
|
|
2023-04-06 19:06:46 +02:00
|
|
|
func NewWarnings(logger *text.Logger) *AURWarnings {
|
|
|
|
if logger == nil {
|
|
|
|
logger = text.GlobalLogger
|
|
|
|
}
|
|
|
|
return &AURWarnings{Ignore: make(stringset.StringSet), log: logger}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (warnings *AURWarnings) AddToWarnings(remote map[string]alpm.IPackage, aurPkg *aur.Pkg) {
|
|
|
|
name := aurPkg.Name
|
|
|
|
pkg, ok := remote[name]
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if aurPkg.Maintainer == "" && !pkg.ShouldIgnore() {
|
|
|
|
warnings.Orphans = append(warnings.Orphans, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if aurPkg.OutOfDate != 0 && !pkg.ShouldIgnore() {
|
|
|
|
warnings.OutOfDate = append(warnings.OutOfDate, name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (warnings *AURWarnings) CalculateMissing(remoteNames []string, remote map[string]alpm.IPackage, aurData map[string]*aur.Pkg) {
|
|
|
|
for _, name := range remoteNames {
|
|
|
|
if _, ok := aurData[name]; !ok && !remote[name].ShouldIgnore() {
|
|
|
|
warnings.Missing = append(warnings.Missing, name)
|
|
|
|
}
|
|
|
|
}
|
2020-07-10 02:36:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (warnings *AURWarnings) Print() {
|
2021-04-03 21:33:56 +02:00
|
|
|
normalMissing, debugMissing := filterDebugPkgs(warnings.Missing)
|
|
|
|
|
|
|
|
if len(normalMissing) > 0 {
|
2023-04-06 19:06:46 +02:00
|
|
|
warnings.log.Warnln(gotext.Get("Packages not in AUR:"), formatNames(normalMissing))
|
2021-04-03 21:33:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(debugMissing) > 0 {
|
2023-04-06 19:06:46 +02:00
|
|
|
warnings.log.Warnln(gotext.Get("Missing AUR Debug Packages:"), formatNames(debugMissing))
|
2020-07-10 02:36:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(warnings.Orphans) > 0 {
|
2023-04-06 19:06:46 +02:00
|
|
|
warnings.log.Warnln(gotext.Get("Orphan (unmaintained) AUR Packages:"), formatNames(warnings.Orphans))
|
2020-07-10 02:36:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(warnings.OutOfDate) > 0 {
|
2023-04-06 19:06:46 +02:00
|
|
|
warnings.log.Warnln(gotext.Get("Flagged Out Of Date AUR Packages:"), formatNames(warnings.OutOfDate))
|
2020-07-10 02:36:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-03 21:33:56 +02:00
|
|
|
func filterDebugPkgs(names []string) (normal, debug []string) {
|
2021-04-05 23:47:29 +02:00
|
|
|
normal = make([]string, 0, len(names))
|
|
|
|
debug = make([]string, 0, len(names))
|
2021-04-03 21:33:56 +02:00
|
|
|
|
|
|
|
for _, name := range names {
|
|
|
|
if strings.HasSuffix(name, "-debug") {
|
|
|
|
debug = append(debug, name)
|
|
|
|
} else {
|
|
|
|
normal = append(normal, name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-04-06 19:06:46 +02:00
|
|
|
func formatNames(names []string) string {
|
|
|
|
return " " + text.Cyan(strings.Join(names, " "))
|
2020-07-10 02:36:45 +02:00
|
|
|
}
|