sources.go 2.3 KB

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