2020-10-01 14:06:21 +02:00
|
|
|
package upgrade
|
|
|
|
|
|
|
|
import (
|
2021-08-12 18:56:23 +02:00
|
|
|
"context"
|
2023-02-21 03:48:56 +01:00
|
|
|
"time"
|
2020-10-01 14:06:21 +02:00
|
|
|
|
|
|
|
"github.com/leonelquinteros/gotext"
|
|
|
|
|
2023-03-07 22:04:06 +01:00
|
|
|
"github.com/Jguer/yay/v12/pkg/db"
|
|
|
|
"github.com/Jguer/yay/v12/pkg/query"
|
|
|
|
"github.com/Jguer/yay/v12/pkg/text"
|
|
|
|
"github.com/Jguer/yay/v12/pkg/vcs"
|
2020-10-01 14:06:21 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func UpDevel(
|
2021-08-12 18:56:23 +02:00
|
|
|
ctx context.Context,
|
2023-03-08 22:30:54 +01:00
|
|
|
log *text.Logger,
|
2023-01-24 00:03:32 +01:00
|
|
|
remote map[string]db.IPackage,
|
2021-02-16 16:49:38 +01:00
|
|
|
aurdata map[string]*query.Pkg,
|
2022-12-18 17:37:15 +01:00
|
|
|
localCache vcs.Store,
|
2022-11-01 23:48:35 +01:00
|
|
|
) UpSlice {
|
2020-10-01 14:06:21 +02:00
|
|
|
toRemove := make([]string, 0)
|
2023-01-24 00:03:32 +01:00
|
|
|
toUpgrade := UpSlice{Up: make([]Upgrade, 0), Repos: []string{"devel"}}
|
2020-10-01 14:06:21 +02:00
|
|
|
|
2023-03-30 20:57:56 +02:00
|
|
|
ctxTimeout, cancel := context.WithTimeout(ctx, 20*time.Second)
|
2023-02-21 03:48:56 +01:00
|
|
|
defer cancel()
|
2023-01-24 00:03:32 +01:00
|
|
|
for pkgName, pkg := range remote {
|
2023-02-21 03:48:56 +01:00
|
|
|
if localCache.ToUpgrade(ctxTimeout, pkgName) {
|
2023-01-24 00:03:32 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-01-24 00:03:32 +01:00
|
|
|
if pkg.ShouldIgnore() {
|
2023-03-08 22:30:54 +01:00
|
|
|
printIgnoringPackage(log, pkg, "latest-commit")
|
2023-01-24 00:03:32 +01:00
|
|
|
continue
|
|
|
|
}
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2021-04-19 13:23:40 +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
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-24 00:03:32 +01:00
|
|
|
localCache.RemovePackages(toRemove)
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2020-10-01 14:06:21 +02:00
|
|
|
return toUpgrade
|
|
|
|
}
|
|
|
|
|
2023-03-08 22:30:54 +01:00
|
|
|
func printIgnoringPackage(logger *text.Logger, pkg db.IPackage, newPkgVersion string) {
|
2020-10-01 14:06:21 +02:00
|
|
|
left, right := GetVersionDiff(pkg.Version(), newPkgVersion)
|
|
|
|
|
2023-03-08 22:30:54 +01:00
|
|
|
logger.Warnln(gotext.Get("%s: ignoring package upgrade (%s => %s)",
|
2020-10-01 14:06:21 +02:00
|
|
|
text.Cyan(pkg.Name()),
|
|
|
|
left, right,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpAUR gathers foreign packages and checks if they have new versions.
|
|
|
|
// Output: Upgrade type package list.
|
2023-03-08 22:30:54 +01:00
|
|
|
func UpAUR(log *text.Logger, remote map[string]db.IPackage, aurdata map[string]*query.Pkg,
|
|
|
|
timeUpdate, enableDowngrade 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
|
|
|
|
2023-01-24 00:03:32 +01: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())) ||
|
2023-04-03 18:37:41 +02:00
|
|
|
(db.VerCmp(pkg.Version(), aurPkg.Version) < 0) ||
|
|
|
|
(enableDowngrade && (db.VerCmp(pkg.Version(), aurPkg.Version) > 0)) {
|
2020-10-01 14:06:21 +02:00
|
|
|
if pkg.ShouldIgnore() {
|
2023-03-08 22:30:54 +01:00
|
|
|
printIgnoringPackage(log, pkg, aurPkg.Version)
|
2020-10-01 14:06:21 +02:00
|
|
|
} else {
|
2021-04-19 13:23:40 +02:00
|
|
|
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,
|
2021-02-05 22:47:03 +01:00
|
|
|
Reason: pkg.Reason(),
|
2020-10-01 14:06:21 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return toUpgrade
|
|
|
|
}
|