sources.go 2.3 KB

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