sources.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package upgrade
  2. import (
  3. "context"
  4. "sync"
  5. "github.com/leonelquinteros/gotext"
  6. "github.com/Jguer/yay/v11/pkg/db"
  7. "github.com/Jguer/yay/v11/pkg/query"
  8. "github.com/Jguer/yay/v11/pkg/text"
  9. "github.com/Jguer/yay/v11/pkg/vcs"
  10. )
  11. func UpDevel(
  12. ctx context.Context,
  13. remote []db.IPackage,
  14. aurdata map[string]*query.Pkg,
  15. localCache *vcs.InfoStore) UpSlice {
  16. toUpdate := make([]db.IPackage, 0, len(aurdata))
  17. toRemove := make([]string, 0)
  18. var (
  19. mux1, mux2 sync.Mutex
  20. wg sync.WaitGroup
  21. )
  22. checkUpdate := func(pkgName string, e vcs.OriginInfoByURL) {
  23. defer wg.Done()
  24. if localCache.NeedsUpdate(ctx, e) {
  25. if _, ok := aurdata[pkgName]; ok {
  26. for _, pkg := range remote {
  27. if pkg.Name() == pkgName {
  28. mux1.Lock()
  29. toUpdate = append(toUpdate, pkg)
  30. mux1.Unlock()
  31. return
  32. }
  33. }
  34. }
  35. mux2.Lock()
  36. toRemove = append(toRemove, pkgName)
  37. mux2.Unlock()
  38. }
  39. }
  40. for pkgName, e := range localCache.OriginsByPackage {
  41. wg.Add(1)
  42. go checkUpdate(pkgName, e)
  43. }
  44. wg.Wait()
  45. toUpgrade := UpSlice{Up: make([]Upgrade, 0), Repos: []string{"devel"}}
  46. for _, pkg := range toUpdate {
  47. if pkg.ShouldIgnore() {
  48. printIgnoringPackage(pkg, "latest-commit")
  49. } else {
  50. toUpgrade.Up = append(toUpgrade.Up,
  51. Upgrade{
  52. Name: pkg.Name(),
  53. Repository: "devel",
  54. LocalVersion: pkg.Version(),
  55. RemoteVersion: "latest-commit",
  56. })
  57. }
  58. }
  59. localCache.RemovePackage(toRemove)
  60. return toUpgrade
  61. }
  62. func printIgnoringPackage(pkg db.IPackage, newPkgVersion string) {
  63. left, right := GetVersionDiff(pkg.Version(), newPkgVersion)
  64. text.Warnln(gotext.Get("%s: ignoring package upgrade (%s => %s)",
  65. text.Cyan(pkg.Name()),
  66. left, right,
  67. ))
  68. }
  69. // UpAUR gathers foreign packages and checks if they have new versions.
  70. // Output: Upgrade type package list.
  71. func UpAUR(remote []db.IPackage, aurdata map[string]*query.Pkg, timeUpdate bool) UpSlice {
  72. toUpgrade := UpSlice{Up: make([]Upgrade, 0), Repos: []string{"aur"}}
  73. for _, pkg := range remote {
  74. aurPkg, ok := aurdata[pkg.Name()]
  75. if !ok {
  76. continue
  77. }
  78. if (timeUpdate && (int64(aurPkg.LastModified) > pkg.BuildDate().Unix())) ||
  79. (db.VerCmp(pkg.Version(), aurPkg.Version) < 0) {
  80. if pkg.ShouldIgnore() {
  81. printIgnoringPackage(pkg, aurPkg.Version)
  82. } else {
  83. toUpgrade.Up = append(toUpgrade.Up,
  84. Upgrade{
  85. Name: aurPkg.Name,
  86. Repository: "aur",
  87. LocalVersion: pkg.Version(),
  88. RemoteVersion: aurPkg.Version,
  89. Reason: pkg.Reason(),
  90. })
  91. }
  92. }
  93. }
  94. return toUpgrade
  95. }