sources.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. text.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(logger *text.Logger, pkg db.IPackage, newPkgVersion string) {
  47. left, right := GetVersionDiff(pkg.Version(), newPkgVersion)
  48. logger.Warnln(gotext.Get("%s: ignoring package upgrade (%s => %s)",
  49. text.Cyan(pkg.Name()),
  50. left, right,
  51. ))
  52. }
  53. // UpAUR gathers foreign packages and checks if they have new versions.
  54. // Output: Upgrade type package list.
  55. func UpAUR(log *text.Logger, remote map[string]db.IPackage, aurdata map[string]*query.Pkg,
  56. timeUpdate, enableDowngrade bool,
  57. ) UpSlice {
  58. toUpgrade := UpSlice{Up: make([]Upgrade, 0), Repos: []string{"aur"}}
  59. for name, pkg := range remote {
  60. aurPkg, ok := aurdata[name]
  61. if !ok {
  62. continue
  63. }
  64. if (timeUpdate && (int64(aurPkg.LastModified) > pkg.BuildDate().Unix())) ||
  65. (db.VerCmp(pkg.Version(), aurPkg.Version) < 0) || enableDowngrade {
  66. if pkg.ShouldIgnore() {
  67. printIgnoringPackage(log, pkg, aurPkg.Version)
  68. } else {
  69. toUpgrade.Up = append(toUpgrade.Up,
  70. Upgrade{
  71. Name: aurPkg.Name,
  72. Base: aurPkg.PackageBase,
  73. Repository: "aur",
  74. LocalVersion: pkg.Version(),
  75. RemoteVersion: aurPkg.Version,
  76. Reason: pkg.Reason(),
  77. })
  78. }
  79. }
  80. }
  81. return toUpgrade
  82. }