sources.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package upgrade
  2. import (
  3. "context"
  4. "github.com/leonelquinteros/gotext"
  5. "github.com/Jguer/yay/v11/pkg/db"
  6. "github.com/Jguer/yay/v11/pkg/query"
  7. "github.com/Jguer/yay/v11/pkg/text"
  8. "github.com/Jguer/yay/v11/pkg/vcs"
  9. )
  10. func UpDevel(
  11. ctx context.Context,
  12. remote map[string]db.IPackage,
  13. aurdata map[string]*query.Pkg,
  14. localCache vcs.Store,
  15. ) UpSlice {
  16. toRemove := make([]string, 0)
  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. text.Warnln(gotext.Get("ignoring package devel upgrade (no AUR info found):"), pkgName)
  22. continue
  23. }
  24. if pkg.ShouldIgnore() {
  25. printIgnoringPackage(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. localCache.RemovePackages(toRemove)
  40. return toUpgrade
  41. }
  42. func printIgnoringPackage(pkg db.IPackage, newPkgVersion string) {
  43. left, right := GetVersionDiff(pkg.Version(), newPkgVersion)
  44. text.Warnln(gotext.Get("%s: ignoring package upgrade (%s => %s)",
  45. text.Cyan(pkg.Name()),
  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(remote map[string]db.IPackage, aurdata map[string]*query.Pkg, timeUpdate, enableDowngrade bool) UpSlice {
  52. toUpgrade := UpSlice{Up: make([]Upgrade, 0), Repos: []string{"aur"}}
  53. for name, pkg := range remote {
  54. aurPkg, ok := aurdata[name]
  55. if !ok {
  56. continue
  57. }
  58. if (timeUpdate && (int64(aurPkg.LastModified) > pkg.BuildDate().Unix())) ||
  59. (db.VerCmp(pkg.Version(), aurPkg.Version) < 0) || enableDowngrade {
  60. if pkg.ShouldIgnore() {
  61. printIgnoringPackage(pkg, aurPkg.Version)
  62. } else {
  63. toUpgrade.Up = append(toUpgrade.Up,
  64. Upgrade{
  65. Name: aurPkg.Name,
  66. Base: aurPkg.PackageBase,
  67. Repository: "aur",
  68. LocalVersion: pkg.Version(),
  69. RemoteVersion: aurPkg.Version,
  70. Reason: pkg.Reason(),
  71. })
  72. }
  73. }
  74. }
  75. return toUpgrade
  76. }