sources.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package upgrade
  2. import (
  3. "context"
  4. "time"
  5. "github.com/leonelquinteros/gotext"
  6. "github.com/Jguer/yay/v12/pkg/db"
  7. "github.com/Jguer/yay/v12/pkg/query"
  8. "github.com/Jguer/yay/v12/pkg/text"
  9. "github.com/Jguer/yay/v12/pkg/vcs"
  10. )
  11. func UpDevel(
  12. ctx context.Context,
  13. log *text.Logger,
  14. remote map[string]db.IPackage,
  15. aurdata map[string]*query.Pkg,
  16. localCache vcs.Store,
  17. ) UpSlice {
  18. toRemove := make([]string, 0)
  19. toUpgrade := UpSlice{Up: make([]Upgrade, 0), Repos: []string{"devel"}}
  20. ctxTimeout, cancel := context.WithTimeout(ctx, 20*time.Second)
  21. defer cancel()
  22. for pkgName, pkg := range remote {
  23. if localCache.ToUpgrade(ctxTimeout, pkgName) {
  24. if _, ok := aurdata[pkgName]; !ok {
  25. log.Warnln(gotext.Get("ignoring package devel upgrade (no AUR info found):"), pkgName)
  26. continue
  27. }
  28. if pkg.ShouldIgnore() {
  29. printIgnoringPackage(log, pkg, "latest-commit")
  30. continue
  31. }
  32. toUpgrade.Up = append(toUpgrade.Up,
  33. Upgrade{
  34. Name: pkg.Name(),
  35. Base: pkg.Base(),
  36. Repository: "devel",
  37. LocalVersion: pkg.Version(),
  38. RemoteVersion: "latest-commit",
  39. Reason: pkg.Reason(),
  40. })
  41. }
  42. }
  43. localCache.RemovePackages(toRemove)
  44. return toUpgrade
  45. }
  46. func printIgnoringPackage(log *text.Logger, pkg db.IPackage, newPkgVersion string) {
  47. left, right := query.GetVersionDiff(pkg.Version(), newPkgVersion)
  48. pkgName := pkg.Name()
  49. log.Warnln(gotext.Get("%s: ignoring package upgrade (%s => %s)",
  50. text.Cyan(pkgName),
  51. left, right,
  52. ))
  53. }
  54. // UpAUR gathers foreign packages and checks if they have new versions.
  55. // Output: Upgrade type package list.
  56. func UpAUR(log *text.Logger, remote map[string]db.IPackage, aurdata map[string]*query.Pkg,
  57. timeUpdate, enableDowngrade bool,
  58. ) UpSlice {
  59. toUpgrade := UpSlice{Up: make([]Upgrade, 0), Repos: []string{"aur"}}
  60. for name, pkg := range remote {
  61. aurPkg, ok := aurdata[name]
  62. if !ok {
  63. continue
  64. }
  65. if (timeUpdate && (int64(aurPkg.LastModified) > pkg.BuildDate().Unix())) ||
  66. (db.VerCmp(pkg.Version(), aurPkg.Version) < 0) ||
  67. (enableDowngrade && (db.VerCmp(pkg.Version(), aurPkg.Version) > 0)) {
  68. if pkg.ShouldIgnore() {
  69. printIgnoringPackage(log, pkg, aurPkg.Version)
  70. } else {
  71. toUpgrade.Up = append(toUpgrade.Up,
  72. Upgrade{
  73. Name: aurPkg.Name,
  74. Base: aurPkg.PackageBase,
  75. Repository: "aur",
  76. LocalVersion: pkg.Version(),
  77. RemoteVersion: aurPkg.Version,
  78. Reason: pkg.Reason(),
  79. })
  80. }
  81. }
  82. }
  83. return toUpgrade
  84. }