sources.go 2.4 KB

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