sources.go 2.3 KB

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