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
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/leonelquinteros/gotext"
|
|
|
|
|
2021-02-16 16:49:38 +01:00
|
|
|
"github.com/Jguer/yay/v10/pkg/db"
|
|
|
|
"github.com/Jguer/yay/v10/pkg/query"
|
2020-10-01 14:06:21 +02:00
|
|
|
"github.com/Jguer/yay/v10/pkg/text"
|
|
|
|
"github.com/Jguer/yay/v10/pkg/vcs"
|
|
|
|
)
|
|
|
|
|
|
|
|
func UpDevel(
|
2021-08-12 18:56:23 +02:00
|
|
|
ctx context.Context,
|
2021-02-16 16:49:38 +01:00
|
|
|
remote []db.IPackage,
|
|
|
|
aurdata map[string]*query.Pkg,
|
2020-10-01 14:06:21 +02:00
|
|
|
localCache *vcs.InfoStore) UpSlice {
|
2021-02-16 16:49:38 +01:00
|
|
|
toUpdate := make([]db.IPackage, 0, len(aurdata))
|
2020-10-01 14:06:21 +02:00
|
|
|
toRemove := make([]string, 0)
|
|
|
|
|
2021-08-11 20:13:28 +02:00
|
|
|
var (
|
|
|
|
mux1, mux2 sync.Mutex
|
|
|
|
wg sync.WaitGroup
|
|
|
|
)
|
2020-10-01 14:06:21 +02:00
|
|
|
|
|
|
|
checkUpdate := func(pkgName string, e vcs.OriginInfoByURL) {
|
|
|
|
defer wg.Done()
|
|
|
|
|
2021-08-12 18:56:23 +02:00
|
|
|
if localCache.NeedsUpdate(ctx, e) {
|
2020-10-01 14:06:21 +02:00
|
|
|
if _, ok := aurdata[pkgName]; ok {
|
|
|
|
for _, pkg := range remote {
|
|
|
|
if pkg.Name() == pkgName {
|
|
|
|
mux1.Lock()
|
|
|
|
toUpdate = append(toUpdate, pkg)
|
|
|
|
mux1.Unlock()
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2020-10-01 14:06:21 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mux2.Lock()
|
|
|
|
toRemove = append(toRemove, pkgName)
|
|
|
|
mux2.Unlock()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for pkgName, e := range localCache.OriginsByPackage {
|
|
|
|
wg.Add(1)
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2020-10-01 14:06:21 +02:00
|
|
|
go checkUpdate(pkgName, e)
|
|
|
|
}
|
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
|
2021-04-19 13:43:13 +02:00
|
|
|
toUpgrade := UpSlice{Up: make([]Upgrade, 0), Repos: []string{"devel"}}
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2020-10-01 14:06:21 +02:00
|
|
|
for _, pkg := range toUpdate {
|
|
|
|
if pkg.ShouldIgnore() {
|
|
|
|
printIgnoringPackage(pkg, "latest-commit")
|
|
|
|
} else {
|
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(),
|
|
|
|
Repository: "devel",
|
|
|
|
LocalVersion: pkg.Version(),
|
|
|
|
RemoteVersion: "latest-commit",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
localCache.RemovePackage(toRemove)
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2020-10-01 14:06:21 +02:00
|
|
|
return toUpgrade
|
|
|
|
}
|
|
|
|
|
2021-02-16 16:49:38 +01:00
|
|
|
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.
|
2021-02-16 16:49:38 +01:00
|
|
|
func UpAUR(remote []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 _, pkg := range remote {
|
|
|
|
aurPkg, ok := aurdata[pkg.Name()]
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timeUpdate && (int64(aurPkg.LastModified) > pkg.BuildDate().Unix())) ||
|
2021-02-16 16:49:38 +01:00
|
|
|
(db.VerCmp(pkg.Version(), aurPkg.Version) < 0) {
|
2020-10-01 14:06:21 +02:00
|
|
|
if pkg.ShouldIgnore() {
|
|
|
|
printIgnoringPackage(pkg, aurPkg.Version)
|
|
|
|
} 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,
|
|
|
|
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
|
|
|
|
}
|