yay/pkg/upgrade/sources.go

92 lines
2.2 KiB
Go
Raw Normal View History

2020-10-01 14:06:21 +02:00
package upgrade
import (
2021-08-12 18:56:23 +02:00
"context"
2020-10-01 14:06:21 +02:00
"github.com/leonelquinteros/gotext"
2021-09-08 22:28:08 +02:00
"github.com/Jguer/yay/v11/pkg/db"
"github.com/Jguer/yay/v11/pkg/query"
"github.com/Jguer/yay/v11/pkg/text"
"github.com/Jguer/yay/v11/pkg/vcs"
2020-10-01 14:06:21 +02:00
)
func UpDevel(
2021-08-12 18:56:23 +02:00
ctx context.Context,
remote map[string]db.IPackage,
aurdata map[string]*query.Pkg,
localCache vcs.Store,
2022-11-01 23:48:35 +01:00
) UpSlice {
2020-10-01 14:06:21 +02:00
toRemove := make([]string, 0)
toUpgrade := UpSlice{Up: make([]Upgrade, 0), Repos: []string{"devel"}}
2020-10-01 14:06:21 +02:00
for pkgName, pkg := range remote {
if localCache.ToUpgrade(ctx, pkgName) {
if _, ok := aurdata[pkgName]; !ok {
text.Warnln(gotext.Get("ignoring package devel upgrade (no AUR info found):"), pkgName)
continue
2020-10-01 14:06:21 +02:00
}
if pkg.ShouldIgnore() {
printIgnoringPackage(pkg, "latest-commit")
continue
}
2021-08-11 20:13:28 +02:00
toUpgrade.Up = append(toUpgrade.Up,
2020-10-01 14:06:21 +02:00
Upgrade{
Name: pkg.Name(),
2022-11-01 23:48:35 +01:00
Base: pkg.Base(),
2020-10-01 14:06:21 +02:00
Repository: "devel",
LocalVersion: pkg.Version(),
RemoteVersion: "latest-commit",
2022-11-01 23:48:35 +01:00
Reason: pkg.Reason(),
2020-10-01 14:06:21 +02:00
})
}
}
localCache.RemovePackages(toRemove)
2021-08-11 20:13:28 +02:00
2020-10-01 14:06:21 +02:00
return toUpgrade
}
func printIgnoringPackage(pkg db.IPackage, newPkgVersion string) {
2020-10-01 14:06:21 +02:00
left, right := GetVersionDiff(pkg.Version(), newPkgVersion)
text.Warnln(gotext.Get("%s: ignoring package upgrade (%s => %s)",
text.Cyan(pkg.Name()),
left, right,
))
}
// UpAUR gathers foreign packages and checks if they have new versions.
// Output: Upgrade type package list.
func UpAUR(remote map[string]db.IPackage, aurdata map[string]*query.Pkg, timeUpdate bool) UpSlice {
2021-04-19 13:43:13 +02:00
toUpgrade := UpSlice{Up: make([]Upgrade, 0), Repos: []string{"aur"}}
2020-10-01 14:06:21 +02:00
for name, pkg := range remote {
aurPkg, ok := aurdata[name]
2020-10-01 14:06:21 +02:00
if !ok {
continue
}
if (timeUpdate && (int64(aurPkg.LastModified) > pkg.BuildDate().Unix())) ||
(db.VerCmp(pkg.Version(), aurPkg.Version) < 0) {
2020-10-01 14:06:21 +02:00
if pkg.ShouldIgnore() {
printIgnoringPackage(pkg, aurPkg.Version)
} else {
toUpgrade.Up = append(toUpgrade.Up,
2020-10-01 14:06:21 +02:00
Upgrade{
Name: aurPkg.Name,
2022-11-01 23:48:35 +01:00
Base: aurPkg.PackageBase,
2020-10-01 14:06:21 +02:00
Repository: "aur",
LocalVersion: pkg.Version(),
RemoteVersion: aurPkg.Version,
Reason: pkg.Reason(),
2020-10-01 14:06:21 +02:00
})
}
}
}
return toUpgrade
}